#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
#include <QtCore> #include <QtGui> int main( int argc, char * argv[]) { QApplication app(argc, argv); QDialog *dialog = new QDialog; QLabel *label = new QLabel(dialog); label->setText( "<font color=red>Hello, World!</font>" ); dialog->show(); return app.exec(); } * This source code was highlighted with Source Code Highlighter .
$ qmake -project
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += main.cpp
$ qmake
$ make
In the first four lines, we include the necessary header files of the graphic elements used - the dialog, buttons, captions and the vertical layout manager. It is not recommended to use such large header files as <QtGui>, <QtCore>, etc. in large projects, as this increases the compilation time.* This source code was highlighted with Source Code Highlighter .
- #include <QDialog>
- #include <QPushButton>
- #include <QLabel>
- #include <QVBoxLayout>
- class MyDialog: public QDialog {
- Q_OBJECT
- public :
- MyDialog (QWidget * parent = 0);
- };
* This source code was highlighted with Source Code Highlighter .
- #include "mydialog.h"
- MyDialog :: MyDialog (QWidget * parent): QDialog (parent) {
- QVBoxLayout * layout = new QVBoxLayout ( this );
- QLabel * label = new QLabel ( this );
- label-> setText ( "<font color = red> Hello, World! </ font>" );
- QPushButton * button = new QPushButton ( this );
- button-> setText ( "Close" );
- layout-> addWidget (label);
- layout-> addWidget (button);
- connect (button, SIGNAL (clicked ()), this , SLOT (close ()));
- }
* This source code was highlighted with Source Code Highlighter .
- #include <QApplication>
- #include "mydialog.h"
- int main ( int argc, char * argv []) {
- QApplication app (argc, argv);
- MyDialog * dialog = new MyDialog;
- dialog-> show ();
- return app.exec ();
- }
$ qmake -project
$ designer
* This source code was highlighted with Source Code Highlighter .
- #include "ui_mydialog.h"
- class MyDialog: public QDialog, public Ui :: Dialog {
- Q_OBJECT
- public :
- MyDialog (QWidget * parent = 0);
- };
* This source code was highlighted with Source Code Highlighter .
- #include "mydialog.h"
- MyDialog :: MyDialog (QWidget * parent): QDialog (parent) {
- setupUi ( this );
- }
Source: https://habr.com/ru/post/50765/
All Articles