New to Qt having fun but...

  • Trying to wrap my head around the whole signal slot thing....

    Qt Creator 2.1.0 - Qt 4.7.1 base
    OpenSuSe GNome
    gcc 4.5.1 Posix Thread Model

    I get the signal slot editor in designer but am sort of stuck on just coding a method, working on the paradigm.

    For Example ( Please don't hate me )...

    In Delphi ( The RAD tool I am most familiar with ) you would take the value of a text box and set a labels value based on a button click ( Really being brief here ) like so...

    button.Click(sender tObject);
    label1.caption := textbox1.text ;

    Now Qlabel has a text property as does a QlineEdit and a QpushButton has a clicked() signal which is synonymous to an event, I think..

    So would I have to define a custom signal to override the clicked() event to say copy the text from the edit control to the label?

    I am not looking to be spoon fed, just trying to understand the paradigm s I can't seem to find any simple examples of doing things like that.

    Thanks so very much in advance....

  • Did you read the "Signals and Slots": introduction? It seems to answer your question more or less.

    Signals are just that: signals. There is nothing that dictates if and how you should react to signals. Slots however are the functional part. You write a function that performs some action, say copy a text from one object (line edit) to another (label). If you define that as being a slot, you get the added option of connecting a signal to it. When you have made the connection, the slot will be executed once an other object (button) fires a signal (clicked()).

  • And remember that a slot is a normal C++ function (member function). Therefore you can perform any action in your slot. For your example, it will give :

    void MyClass::onMyButtonClicked()

    And btw, welcome and have fun with Qt :)

Log in to reply