eventloop.cpp

来自「压缩包里有教材<<C++模式设计-基于QT4开源跨平台开发框架&gt」· C++ 代码 · 共 57 行

CPP
57
字号
//start id=setgui#include <QApplication>#include <QPushButton>#include <QTextEdit>#include <QVBoxLayout>#include <QDebug>#include "messager.h"/** First interactive GUI application    Uses buttons, signals and slots.*/QWidget* setGui(QWidget *box) {    QLayout* layout = new QVBoxLayout;    box->setLayout(layout); /* box is the parent of layout. */    QTextEdit *te = new QTextEdit; /* window for qDebug messages */    layout->addWidget(te); /* add as grandchild to box */    te->setHtml("Some <b>text</b> in the <tt>QTextEdit</tt>"        "edit window <i>please</i>?");    QPushButton *quitButton=new QPushButton("Quit");    layout->addWidget(quitButton);    QPushButton *shoutButton = new QPushButton("Shout");    layout->addWidget(shoutButton);    Messager *msgr = new Messager("This dialog will self-destruct.", box);    QObject::connect(quitButton, SIGNAL(clicked()),                  qApp, SLOT(quit())); /* qApp is a global variable that                  points to the current QApplication object. */    qApp->connect(shoutButton, SIGNAL(clicked()), msgr, SLOT(shout()));    return box;}//end//start id=mainint main(int argc, char * argv[]) {    QApplication myapp(argc, argv); /* Every GUI, multithreaded,                   or event-driven Qt Application must have                   a QApplication object defined at the top                   of main(). */    QWidget rootWidget;    setGui(&rootWidget);    rootWidget.show();  /* Show the widget on the screen. */    return myapp.exec();  /* Enter an event loop. */};//end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?