LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   qt connect a signal to a class function (https://www.linuxquestions.org/questions/programming-9/qt-connect-a-signal-to-a-class-function-4175483912/)

knobby67 11-08-2013 11:48 AM

qt connect a signal to a class function
 
Hi All,
first let me say I'm an embedded programmer who as to do some work on a gui to connect a device. I've been asked to do it in QT. This is my first day working in QT so I'm unfamiliar with the correct wording so hope this explains. I've done some googling but am unable to find and answer, there seems to be a host of documents, but I really can't find an answer :s
So, I produced a basic gui in designer on linux/ubuntu. I've added a couple of labels and line edits, so I can fill line edit, eg name and version. All works OK.
I then added a cpp/h/class files called example, the class contains a sdt::string name and version. I've added a signal pointing to the line edits for name and version, that on pressing return do a slot. However the slots give me lots of options clear() repaint() ect. I can see they work, eg use clear() and hit return the name I've typed vanishes ect. However I want the signal to point to the class I produced and fill in the name version strings when return is pressed. So basically when I type in the box and hit return my own class string variable is populated with the name I've typed in.
Sorry I'm really brand new to QT and am unsure if my language / terms are correct, so its rather hard to explain.

Thanks for the help

rtmistler 11-08-2013 02:58 PM

You want to do something like this, correct?

Code:

-- somewhere else; where you define your custom class

slots:
    void do_this_because_the_button_was_clicked();
    // NOTE it must be under the slots: hierarchy to be usable as a connection point.

-- Your code

QPushButton *myButton = new QPushButton("HIT ME");

connect(this->myButton, SIGNAL(clicked()), this, SLOT(do_this_because_the_button_was_clicked()));

Qt and the associated forums offer many examples; however for someone not well initiated with their programming model, or other similar models, it's a bit daunting to start.

Signals and Slots

I started with this book but the version for Qt4, it helped but eventually one moves to checking for examples very rapidly. What I recommend is that you follow the initial examples and don't try to do the nice and pretty styling stuff you eventually want to have it look like; you first need to understand their programming model before you can start varying things outside their default boxes.

Recommended Reading

knobby67 11-09-2013 04:39 AM

Thanks for the links, ill make them my weekend reading.
Like some other api stuff ive worked with in the past there's such a huge amount of info with much being out of it out of date it makes starting a daunting task.


All times are GMT -5. The time now is 11:39 PM.