User Tools

Site Tools


qt:two_widgets

From Molkentin:

main.cpp
// helloWorld/main.cpp
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QLabel label("Hello World");
    label.show();
    return a.exec();
}
 
// layout/main.cpp
#include <QApplication>
#include <QVBoxLayout>
#include <QLabel>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);                             // app on the stack
    QWidget window;                                         // main widget on the stack
    QVBoxLayout* mainLayout = new QVBoxLayout(&window);     // everyting else on the heap
    QLabel* label1 = new QLabel("One");
    QLabel* label2 = new QLabel("Two");
    mainLayout->addWidget(label1);                          // label1 becomes a child of mainLayout's parent
    mainLayout->addWidget(label2);                          // ditto
    window.show();
    return a.exec();
}
qt/two_widgets.txt · Last modified: 2010/12/09 20:47 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki