Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. SLOT DOUBT
Qt 6.11 is out! See what's new in the release blog

SLOT DOUBT

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 2.4k Views 2 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.
  • R Offline
    R Offline
    R P Shah
    wrote on last edited by
    #1

    Hello,
    I am new in QT.
    Help me to solve my doubt.
    I don't get it why slot function is not called.

    Main.CPP file
    -------------------
    
    #include <QApplication>
    #include "pushbutton.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        pushbutton1 push;
        push.show();
    //    push.window.show();
        return app.exec();
    }
    
    pushbutton.h file
    -------------------------
    #ifndef PUSHBUTTON_H
    #define PUSHBUTTON_H
    
    #include <QWidget>
    #include <QLabel>
    #include <QPushButton>
    #include <QLineEdit>
    #include <QMessageBox>
    #include <QMainWindow>
    
    class pushbutton1 : public QWidget
    {
    
    public:
        explicit pushbutton1();
        ~pushbutton1();
    //    QWidget window;
        QMessageBox box;
    
    private slots:
        void popup();
    
    private:
    
    QLabel *Label;
    QPushButton *ok;
    QPushButton *cancel;
    QLineEdit line;
    
    };
    
    #endif // PUSHBUTTON_H
    
    pubutton.cpp file
    -------------------------
    #include <iostream>
    #include <QDebug>
    #include "pushbutton.h"
    #include "main.cpp"
    
    void pushbutton1 :: popup()
    {
        qDebug() << "Hello How are you?";
    //    cout << "Hello" << endl;
    //    QMessageBox::information(this, "Line MSG", line.text());
        box.setText(line.text());
        box.show();
    }
    
    pushbutton1::pushbutton1()
    {
        //class Rushin r1;
    
        Label = new QLabel("Enter Text:",this);
        Label->resize(90,30);
        Label->setStyleSheet("background-color:white;border-style: outset;\
                            border-width: 1px; border-color: black;");
    
    //    line = new QLine("0",&window);
        //line("",&window);
        line.setParent(this);
        line.resize(100,30);
        line.move(95,0);
        line.setStyleSheet("border-style: outset;\
                            border-width: 1px; border-color: black;");
    
        ok = new QPushButton("OK",this);
        ok->move(50,35);
        ok->resize(50,30);
    
        cancel = new QPushButton("Cancel",this);
        cancel->move(110,35);
        cancel->resize(50,30);
    
    //    box.setParent(&window);
        box.resize(100,100);
        box.setWindowTitle("Display");
        box.setText(line.text());
    
        connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
        connect(&line, SIGNAL(returnPressed()), SLOT(popup()));
        connect(ok, SIGNAL(clicked()), SLOT(popup()));
    
    //    window.show();
    
    }
    
    pushbutton1::~pushbutton1()
    {
    
    }```
    //your code here
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You're missing the Q_OBJECT macro in your class declaration.

      On a side note, it's Qt, QT stands for Apple QuickTime which you might also be using ;)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        hi
        You need Q_OBJECT in your class for signals to work
        like
        class pushbutton1 : public QWidget
        {
        Q_OBJECT

        After adding this, please run qmake. Normal compile is not enough.

        Also as trick.
        use
        qDebug() to see if connect is true. so u know if it is ok

        qDebug() << "result: " << connect(ok, SIGNAL(clicked()), SLOT(popup()));

        (#include <QDebug>)

        R 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          You're missing the Q_OBJECT macro in your class declaration.

          On a side note, it's Qt, QT stands for Apple QuickTime which you might also be using ;)

          R Offline
          R Offline
          R P Shah
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • mrjjM mrjj

            hi
            You need Q_OBJECT in your class for signals to work
            like
            class pushbutton1 : public QWidget
            {
            Q_OBJECT

            After adding this, please run qmake. Normal compile is not enough.

            Also as trick.
            use
            qDebug() to see if connect is true. so u know if it is ok

            qDebug() << "result: " << connect(ok, SIGNAL(clicked()), SLOT(popup()));

            (#include <QDebug>)

            R Offline
            R Offline
            R P Shah
            wrote on last edited by
            #5

            @mrjj :
            Hello,
            As per your explanation, I have changed in my code but now It shows compilation error
            like below.
            undefined reference to 'vtable for pushbutton1' and Id returned 1 exit status.
            Please solve it.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Do as @mrjj suggested: re-run qmake before building or do a full rebuild.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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