Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Signal/slot doesn’t work

    General and Desktop
    3
    7
    2410
    Loading More Posts
    • 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
      silep last edited by

      Hello,

      I am practicing Qt5 and I tried some easy signal/slots which worked, but now I tried to open a Dialogwindow with a connect and it doesn't work. I really don't know why.. I tried to open only the window in the main and it worked, so the problem comes probably from the connect line.

      MaFenetre.h

      @class MaFenetre: public QWidget
      {
      public:
      MaFenetre();
      ~MaFenetre();
      void show();

      public slots:
      void OuvrirDialogueQuestion();

      private:
      QWidget *cadre;
      QPushButton *bouton2;
      };@

      MaFenetre.cpp

      @MaFenetre::MaFenetre()
      {
      cadre = new QWidget;
      cadre->setFixedSize(1905,1005);

      bouton2 = new QPushButton("Question!",cadre);
      bouton2->setFont(QFont("Lucida Handwriting",20));
      bouton2->move(300,900);
      QObject::connect(bouton2, SIGNAL(clicked()), this , SLOT(OuvrirDialogueQuestion()));

      MaFenetre::~MaFenetre()
      {
      delete bouton1;
      delete bouton2;
      delete lcd;
      delete slider1;
      delete slider2;
      delete barre;
      delete cadre;
      }

      void MaFenetre::show()
      {
      cadre->show();
      }

      void MaFenetre::OuvrirDialogueQuestion()
      {
      QMessageBox::question(this,"Question","Est ce que tu aimes les nems?", QMessageBox::Yes | QMessageBox::No);
      }@

      main.h

      @int main (int argc, char *argv[])
      {

      QApplication app(argc, argv);
      MaFenetre window;
      window.show();

      return app.exec();
      }@

      Would anyone have an idea about where the error could be? If you have any advice about this program, I would be interested to read them too. Thank you in advance!

      qxoz: moved

      1 Reply Last reply Reply Quote 0
      • S
        silep last edited by

        Oups sorry I am not in the good topic folder, but I don't know how to delete my topic

        1 Reply Last reply Reply Quote 0
        • mranger90
          mranger90 last edited by

          You need a Q_OBJECT designation in your class declaration.
          @
          class MaFenetre: public QWidget
          {
          Q_OBJECT
          public:
          MaFenetre();
          ~MaFenetre();
          void show();

          public slots:
          void OuvrirDialogueQuestion();

          private:
          QWidget *cadre;
          QPushButton *bouton2;
          };
          @

          1 Reply Last reply Reply Quote 0
          • M
            mlong last edited by

            Be sure and add a Q_OBJECT macro in your class. You may need to run qmake again, too.

            [Edit: Oops, didn't see mranger90's response.]

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply Reply Quote 0
            • S
              silep last edited by

              Thank you very much, it works now!

              1 Reply Last reply Reply Quote 0
              • M
                mlong last edited by

                Good deal! Be sure and edit your first post to add [Solved] to the beginning of the title! Thanks!

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply Reply Quote 0
                • S
                  silep last edited by

                  ok

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post