[Solved] Signal/slot doesn’t work



  • 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



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



  • 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;
    };
    @


  • Moderators

    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.]



  • Thank you very much, it works now!


  • Moderators

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



  • ok


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.