Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:32:06+00:00 2026-05-29T07:32:06+00:00

I have this code: #include <gtkmm.h> #include <unistd.h> void send_msg(Gtk::Entry* entry, int* fd); Glib::ustring*

  • 0

I have this code:

#include <gtkmm.h>
#include <unistd.h>


void send_msg(Gtk::Entry* entry, int* fd);
Glib::ustring* receive_msg(int* fd);
bool handle_msg(Gtk::Label* lbl, int* fd);




int main()
{
    pid_t pid = fork();

    int fd[2];
    pipe(fd);

    Gtk::Main gtkmain;
    Gtk::Window* win;
    Glib::RefPtr<Gtk::Builder> builder;

    if (pid > 0)
    {
        close(fd[1]);

        builder = Gtk::Builder::create_from_file("parent.glade");
        builder->get_widget("parentwin", win);

        Gtk::Label* lbl;
        builder->get_widget("label", lbl);
        sigc::slot<bool> timer = sigc::bind(sigc::ptr_fun(&handle_msg), lbl, fd);
        Glib::signal_timeout().connect(timer, 1000);
    }
    else if (pid == 0)
    {
        close(fd[0]);

        builder = Gtk::Builder::create_from_file("child.glade");
        builder->get_widget("childwin", win);

        Gtk::Button* send;
        Gtk::Entry* txt;
        builder->get_widget("send", send);
        builder->get_widget("msg", txt);
        send->signal_clicked().connect(sigc::bind(sigc::ptr_fun(&send_msg), txt, fd));
    }

    Gtk::Main::run(*win);

    return EXIT_SUCCESS;
}







void send_msg(Gtk::Entry* entry, int* fd)
{
    Glib::ustring msg = entry->get_text();
    const char* c_msg = msg.c_str();

    int i = 0;
    char* c = new char(0);

    while (*c = c_msg[i++])
    {
        write(fd[1], c, 1);
    }
}



Glib::ustring* receive_msg(int* fd)
{
    Glib::ustring* msg = new Glib::ustring;
    char* c = new char(0);

    do
    {
        read(fd[0], c, 1);
        msg->append(c);
    } while (*c);

    return msg;
}



bool handle_msg(Gtk::Label* lbl, int* fd)
{
    Glib::ustring* msg;
    msg = receive_msg(fd);
    lbl->set_text(*msg);
    // delete msg;
    return true;
}

and it’s purpose is this:
The whole program works similar to a chat program, just not intended for that. The child process brings up a window with an Entry and a Button in it, to send the contents of Entry using a low level code that uses write() function, and the parent brings up a window with just a Label in it to display the data received at low level with read().

The exact functionality that I’m after I could achieve without gtkmm, but even when I write the read() and write() codes right before gtkmm parts under close() to test the functionality of read/write as a test to bypass function calls, it still won’t work.

The only possibility I can think of, is an incompatibility between unistd.h and gtkmm.h.

(and also I know the code is a bunch of dirt in writing, to some extent, but its a practice, forget that! 😉 )

Thanks so much for your helps 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:32:07+00:00Added an answer on May 29, 2026 at 7:32 am

    Your pipe-management code is wrong. You’re supposed to pipe() before you fork(), to make sure both file descriptors are inherited into the child process. Read up on the documentation of these functions.

    Here is a quite dense tutorial on Unix programming, it’s clearly visible that pipe() is more or less the first call made, before launching the child process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code: #include <iostream> #include <fstream> using namespace std; int main(void)
I have this code: #include <stdio.h> int getAns(void); int num; int main() { int
have a look at this code: #include<stdio.h> #include <unistd.h> int main() { int pipefd[2],n;
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: #include <iostream> #include <functional> struct A { int operator()(int i)
I have this code #include <iostream> using namespace std; class Test{ public: int a;
I have this code: #include <stdio.h> #include <wchar.h> int main() { wchar_t *foo =
I have this code below #include <stdio.h> int main(){ int i=0; for(i=0; i<1000; i++)
I have this code main.cpp #include <iostream> #include functs.h using namespace std; int main()
I have this simple code #include <stdio.h> #include <OpenGL/glext.h> #include <OpenGL/gl.h> int main (int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.