PDA

View Full Version : Starting building QT projects



FuryCradle
25th September 2009, 05:48
Hello,

I am new to QT.. well my question is probably is a basic C++ thingy anyway..

I want to develop the application and having in mind that i should make each window in it's own c++ file, for a start i want to have the main.cpp to only contain the basic application setup, then develop the mainwindow in another c++ file, for example:

main.cpp:

#include "main.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);

return a.exec();
}


then have a mainwindow class in another c++ file

mainWindow.cpp

#include <QMainWindow>

class MainWindow : public QMainWindow
{
public:
MainWindow();

};

MainWindow::MainWindow()
{
setWindowTitle("Test");
}

now i want to know how to add the MainWindow class to the app in main.cpp? i mean how to add it to the application then call it from there?

yogeshgokul
25th September 2009, 05:59
Thats easy.


#include "main.h"
#include <QApplication>
#include "MainWindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow mw;
mw.show();
return a.exec();
}

FuryCradle
25th September 2009, 06:03
Thats easy.


#include "main.h"
#include <QApplication>
#include "MainWindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow mw;
mw.show();
return a.exec();
}

thank you, that's what i did, but i get this error:
C:/Qt/2009.03/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/locale_facets.tcc:2498: undefined reference to `vtable for MainWindow'

FuryCradle
25th September 2009, 06:06
nevermind, i sorted it out, thank you very much :D