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] using customized QPushButton on QWizard
Forum Updated to NodeBB v4.3 + New Features

[Solved] using customized QPushButton on QWizard

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 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.
  • G Offline
    G Offline
    gor kogalo
    wrote on last edited by
    #1

    Hello every one. I want to use a QPushButton on QWizardPage. I have implemented the qwizard pages and added QPushButton as follows in the code bellow. When I click the button, the signal and slot connection does not work. Any idea on how to go around it? Thanks in advance for your response.

    @class DatabasePage : public QWizardPage
    {

    public:
    DatabasePage();

    int nextId() const;
    

    private slots:
    void connectionTest();

    private:
    QPushButton *testConnBttn;
    };@
    @DatabasePage::DatabasePage()
    {
    .....
    testConnBttn = new QPushButton(tr("Test connection"));
    QHBoxLayout *bttnLayout = new QHBoxLayout;
    bttnLayout->addStretch();
    bttnLayout->addWidget(testConnBttn);

    setLayout(bttnLayout);
    connect(testConnBttn, SIGNAL(clicked()), this, SLOT(connectionTest()));
    

    }
    @
    @void DatabasePage::connectionTest()
    {
    QMessageBox::information(this,"WATCH","Error");

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName( "localhost");
    db.setDatabaseName( "test" );
    db.setUserName( "root" );
    db.setPassword( "hqo" );
    if ( !db.open() )
    {
        QMessageBox::information(this,"WATCH",db.lastError().text());
    }
    

    }
    @

    Gor

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      when the connection fails the reason will be printed to the console.
      Also you can check the boolean return value of the connect-statement indicating if it failed or succeeded.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gor kogalo
        wrote on last edited by
        #3

        Thanks for the response. On the Application Output console, this is what I get:
        @Object::connect: No such slot QWizardPage::connectionTest() in ../smif/setupwizard.cpp:272@

        Gor

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          you're missing the Q_OBJECT macro ;)
          @
          class DatabasePage : public QWizardPage
          {
          Q_OBJECT
          ....
          }
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

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

            Hi,

            You are missing the Q_OBJECT macro in your DatabasePage declaration

            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
            • G Offline
              G Offline
              gor kogalo
              wrote on last edited by
              #6

              Thanks for pointing this out. Initially I had this macro and the error was the same.

              Gor

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

                Where do you declare your DatabasePage class ?

                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
                • G Offline
                  G Offline
                  gor kogalo
                  wrote on last edited by
                  #8

                  I have declared it in my setupWizard header file. This is how I have done it:
                  @
                  class setUpWizard : public QWizard
                  {
                  public:
                  enum { Page_Intro, Page_Admin, Page_School, Page_Subjects,
                  Page_Database, Page_Conclusion };
                  setUpWizard();
                  protected:

                  private slots:
                  void showHelp();

                  };
                  class DatabasePage : public QWizardPage
                  {

                  public:
                  DatabasePage();

                  int nextId() const;
                  

                  private slots:
                  void connectionTest();

                  private:
                  QPushButton *testConnBttn;
                  };@

                  I get the following error when I assign Q_OBJECT macro to both setUPWizard class and DatabasePage class
                  @
                  C:\Users\GORDON\project\smif-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug..\smif\setupwizard.cpp:202: error: undefined reference to `vtable for DatabasePage'
                  @

                  Gor

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

                    This error usually appears when you didn't re-run qmake after adding/removing Q_OBJECT

                    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
                    • G Offline
                      G Offline
                      gor kogalo
                      wrote on last edited by
                      #10

                      thanks I re-run qmake and it is now working.....I glad for your help

                      Gor

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

                        You're welcome :)

                        Since it's working, you can update the thread's title by prepending [solved] so other forum users will know a solution has been found :)

                        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