Sometimes you need to create a very simple single file application in Qt4. However it's problematic since you are always doing the CPP/H separation, and then the main() is in another file...
Any ideas how to do this in a single file? As quick as dirty as possible.
This is an example that shows how to do this in a single file. Just throw this in a new directory, save it as "main.cpp" and then run qmake -project; qmake; make
to compile.
#include <QtGui/QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0){
button = new QPushButton("Hello, world!", this);
}
private:
QPushButton *button;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "main.moc"
Two tricks in this demo: