Re: What is the minimum number of lines to update a gui window without user clicking a button



On 08/10/2013 11:45 AM, Chris Vine wrote:
Your posts are no doubt highly meritorious but I am afraid they are not
offering much clarification.  You would probably make your point better
if you shortened your posts by roughly an order of magnitude.  However,
after cutting through the dense undergrowth, I still think you have
failed to understand how programs using event loops work.  If the
program is not just running a single batch of instructions, it has to
have a loop in there somewhere, which is blocking until there is
something to process.  The simplest loop for your console program would
involve blocking on select() or poll(), for which purpose presumably
you must have a file descriptor to poll on.  In that case, as I said,
you can do the same with Glib::signal_io().connect().  Or maybe you are
polling using timeouts, in which case the equivalent for gtkmm is
Glib::signal_timeout().connect().
Chris, thanks again for your interest in my question.  I apologize for the delayed response, as I was on a support call for most of the day.  When I got back I trimmed down 500 lines of code to the example below.

This is 48 lines of my vpn connection routine. It's 48 out of the 500 line application. In those 48 lines I have 4 lines outputting to the console. I would like for those lines to output to a gui window.

Those 4 lines are just some of the actually 25 lines of status that will be output in the course of running the application. While it's running and checking the connection it outputs either starts “*” or dots “.” at 10 second interval while it checks some of the file and connection status.


// code begin
// -------------------------------------------------
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
    string ret;
    string server;
    string command;
    string runit(string c);
    setuid(0);
    server = argv[1];
    string peerentry = "/etc/ppp/peers/" + server;
    command = "ls " + peerentry;
    ret = runit(command);
    if (ret != peerentry)    {
        cout << "Problems locating server: " << server << endl; // console out
        return 1;
    }
    string filetest = "/var/run/ppp-" + server + ".pid";
    ifstream myfile(filetest.c_str());

    if (myfile.is_open()){
        cout << "Connection is in effect" << endl; // console out
        myfile.close();
    }
    else    {
        cout << "Connecting to..." << server << endl; // console out
        command = "pppd call " + server;
        ret = runit(command);
        cout << "Results: [" << ret << "]" << endl; // console out
    }
    return 0;
}
string runit(std::string c){
    string lret = "";
    c += " 2>&1";
    FILE *in;
    char buff[512];
    if (!(in = popen(c.c_str(), "r")))    {
        return lret;
    }
    while (fgets(buff, sizeof(buff), in) != NULL)    {
        lret += buff;
    }
    pclose(in);
    return lret;
}
// -------------------------------------------------
// code end

-- L. James

--
L. D. James
ljames apollo3 com
www.apollo3.com/~ljames


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]