[Solved] using customized QPushButton on QWizard
-
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()); }
}
@ -
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. -
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@ -
you're missing the Q_OBJECT macro ;)
@
class DatabasePage : public QWizardPage
{
Q_OBJECT
....
}
@ -
Hi,
You are missing the Q_OBJECT macro in your DatabasePage declaration
-
Thanks for pointing this out. Initially I had this macro and the error was the same.
-
Where do you declare your DatabasePage class ?
-
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'
@ -
This error usually appears when you didn't re-run qmake after adding/removing Q_OBJECT
-
thanks I re-run qmake and it is now working.....I glad for your help
-
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 :)