I am new to Qt. I created a basic form with 4 buttons: btn_DoSomething , btn_Clear, btn_About, btn_Browse. I used qmake-qt4 to generate the header file containing my form info (ui_myqtapp.h).
I then created this header file:
Looks good so far, right? Then I implemented the functions defined in the slots, and connected them to the 4 buttons:
Finally, I created the "main" file:
It compiles fine but I get this linker error:
in line 5 of myqtapp.cpp (myQtApp::myQtA pp( QWidget* parent ))
I then created this header file:
Code:
// myqtapp.h:
#ifndef MYQTAPP_H
#define MYQTAPP_H
#include "ui_myqtapp.h"
class myQtApp : public QWidget, private Ui::frmMain
{
Q_OBJECT
public:
myQtApp(QWidget* parent = 0);
public slots:
void getPath();
void doSomething();
void clear();
void about();
};
#endif
Code:
// myqtapp.cpp:
#include <QtGui>
// if we include <QtGui> there is no need to include every class used: <QString>, <QFileDialog>,...
#include "myqtapp.h"
myQtApp::myQtApp( QWidget* parent )
{
setupUi(this); // Set up the GUI
// signals / slots mechanisms in action -> link a action in the GUI to a subroutine in this class
connect( btn_Browse, SIGNAL(clicked()), this, SLOT(getPath()) );
connect(btn_DoSomething,SIGNAL(clicked()), this, SLOT(doSomething()) );
connect( btn_Clear, SIGNAL(clicked()), this, SLOT(clear()) );
connect( btn_About, SIGNAL(clicked()), this, SLOT(about()) );
}
Code:
// main.cpp:
#include <QApplication>
#include "myqtapp.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
myQtApp* dialog = new myQtApp;
dialog->show();
return app.exec();
}
Code:
/home/jBrandt/Code/qt/myqtapp.cpp|5|undefined reference to `vtable for myQtApp'|
Comment