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. [Solved] Signal/slot doesn’t work
QtWS25 Last Chance

[Solved] Signal/slot doesn’t work

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.7k Views
  • 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
    silep
    wrote on last edited by
    #1

    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
    0
    • S Offline
      S Offline
      silep
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          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
          0
          • S Offline
            S Offline
            silep
            wrote on last edited by
            #5

            Thank you very much, it works now!

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              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
              0
              • S Offline
                S Offline
                silep
                wrote on last edited by
                #7

                ok

                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