Qt World Summit: Register Today!

Beginners: signal slot help

  • hello guys,

    I ve a class and in this class I create a new QWidget to show an image. I want to get the signal when this QWidget is closed, or even the possibility to know if it is open or closed.

    here is how I build it from inside my class. the connect has a mistake.

    QWidget *blub;


            QWidget *blub = new QWidget();
            blub->setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMaximizeButtonHint); //no resize


  • The connect() should read:


    However, there is a difference between closed, as in hidden, and destroyed where the object is being torn down (after a delete or going out of scope). QWidget::visible() will tell you if the widget is visible. You can use the QWidget::closeEvent() (in the blub object) to do pre-close processing if that suits your purposes.

  • Use a QPointer instead of a naked pointer. This will save you later on. The QPointer will null itself when the Widget is freed.

    Then call
    setAttribute( Qt::WA_DeleteOnClose, true );
    on your widget it will delete itself when closed.
    And because you use a QPointer the pointer will be null as well.

  • What is QPointer can you give me an example?

    I tried the connect as stated above but it did not work, unfortunately, do i miss something else? Should I create it as a class?

  • @
    QPointer<QWidget> blub;
    blub = new QWidget():

    A QPointer is just Qt's class wrapper for Qt dynamic memory.

  • is it possible say to get keyboard events from the main widget irregardless which (it or blub) has focus.

    can i put in the main widget @this->grabkeyboard();@ ?

  • hello m usind qt designer for first time.. i need to create a calculator using three line edits and two pushbutoons for addition and equality.
    cn anyone help me with the code using signals and slots??

  • see this video to learn more about signal and slots

  • hello hav to design a calculator in which if a value becomes more than 10 color of button changes to red otherwise green..
    plzzz help me with the code

  • You can connect the textChanged() signal of the lineEdit to a slot where you can check the count using
    lineEdit->text().length() you can also set the maxlengh like lineEdit->setMaxLength().

Log in to reply