Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Beginners: signal slot help
Forum Updated to NodeBB v4.3 + New Features

Beginners: signal slot help

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #1

    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.

    myclass.h
    @
    private:
    QWidget *blub;
    @

    @myclass.cpp

            QWidget *blub = new QWidget();
            blub->resize(250,230);
            blub->setWindowFlags((windowFlags() | Qt::CustomizeWindowHint) & ~Qt::WindowMaximizeButtonHint); //no resize
            connect(blub,SIGNAL(destroyed(blub)),this,SLOT(handwindowcloseevent()));
    

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      The connect() should read:

      @connect(blub,SIGNAL(destroyed()),this,SLOT(handwindowcloseevent()));
      @

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pwnstar23
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SherifOmran
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pwnstar23
            wrote on last edited by
            #5

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

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SherifOmran
              wrote on last edited by
              #6

              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();@ ?

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rapunzel
                wrote on last edited by
                #7

                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??

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SherifOmran
                  wrote on last edited by
                  #8

                  see this video to learn more about signal and slots
                  https://www.youtube.com/watch?v=GxlB34Cn0zw

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rapunzel
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Sam
                      wrote on last edited by
                      #10

                      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().

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved