Re: How to update both the Console and the GTKMM gui window after running other functions



You said:
-----------------------------------------------------------------------------
You're problem is that your "myLabel" class isn't a label but a window. You're deriving it from Gtk::Window.
Normally, you wouldn't derive your own label, I wonder what you wanted to accomplish with that...
-----------------------------------------------------------------------------

I'm sure your question is rhetoric.  However I'll clarify it anyway.  I'm very novice when it comes to classes and gtkmm.  I'm so new to gtkmm that I haven't up to this point written anything that actually works except to copy a few examples and look at them.  I still don't fully understand them.

None of the examples I have found has a functionality to be able to append to data that is presented without the user clicking a button.

I'm trying to get a window that has text data in it and have a way to continue with various c++ functions that will log the output to the gui window while at the same time logging the output to std::cout.

I wrote something very crude in an effort to clarify what I'm trying to do.

I cleaned my progress up as much as I could to something that would actually compile and give an idea of how far I have getting in attempting to achieve what I have described.

If I were a little more confused about C++ and showed a line: (cin << "Hello" << endl;) and said I was trying to print hello to the console, it should be clear to a C++ programer and novice such as me as well to understand what is wrong with the line and to advise that "cin" is for console in and "cout" is for console out.  I hope it would be known by my description of what I'm trying to accomplish.  At present, the code isn't doing it, because I don't know exactly what code to type to accomplish what I'm describing in my summary.

I appreciate your input... and again, I'm sure your comment was rhetoric.

I studied and compiled your example without errors.  The output is identical to my crude attempt.  There is no text in the window.  I appreciate your line by line description.  When I find a way to get it to actually work I'll keep it as reference and continue to study the line by line examples to more fully digest the details.

As far as using signals, if it turns out that is the only way to accomplish my objective, I'll eventually get around to it, because I will stay with it until it's working.  I'm not intentionally eliminating anything.  I'm just trying to have a gui window set that I can continually update from a function, ie (myfunction()).

By the way, the closest that I could find on the gtkmm example site is the progress bar example.  I spent a lot of time studying it, but at present it was too complicated for me to figure out how to remove all the buttons, show a text screen and where to place my function.

-- L. James

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

On Thu, 2013-08-01 at 02:27 +0200, Jonas Platte wrote:
You're problem is that your "myLabel" class isn't a label but a window. You're deriving it from Gtk::Window.
Normally, you wouldn't derive your own label, I wonder what you wanted to accomplish with that...

To make clear how you would structure your code with an own Window class normally, here is a new example:


#include <gtkmm.h>

class myWindow : public Gtk::Window
{
protected:
    Gtk::Label myLabel;

public:
    myWindow();
   
    void set_main_label(Glib::ustring); // Glib::ustring is just another string class. It's used by gtkmm and is fully compatible with std::string
}

myWindow::myWindow()
// instead of set_text, you could also pass the string to be shown by the label in its constructor:
: myLabel("Hello...") // constructing myLabel with "Hello..." as argument
{
    myLabel.set_text("Hello..."); // setting myLabel's text via method
    add(myLabel); // I read you used Java somewhen, there the syntax would be "this->add(myLabel);". You just don't need the "this->" in C++
}

// you could also just make myLabel public, but I consider that bad style
void myWindow::set_main_label(Glib::ustring str)
{
    myLabel.set_text(str);
}

int main()
{
    Gtk::Main kit(argc, argv);
   
    myWindow win;

    win.set_main_label("Changed the text");   
   
    kit.run(win); // if you declare that kit thing, you should also use it instead of the static function ^^
    return 0;
}


The thing is, you have only got one thread here. And the window is when calling run, not before. This was just to make clear how to structure it. Adding a seperate thread would be much too complicated I think. You should understand how to let the program react the certain events first, I think. And for your purpose it would be enough to change the label after a certain amount of time, thus a timeout signal, right?

One last thing: When you call set_text of a Gtk::Label, and then change the string passed to set_text, that won't affect the label. You normally would just call set_text every time instead of changing some string (but you could even simply derive your own Label class to get that behaviour).




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