#include <QtGui/QApplication>#include "qt_hello_world.h"int main(int argc, char *argv[]){ QApplication a(argc, argv); qt_hello_world w; w.show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
#include "qt_hello_world.h"qt_hello_world::qt_hello_world(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags){ ui.setupUi(this);}qt_hello_world::~qt_hello_world(){}
#ifndef QT_HELLO_WORLD_H#define QT_HELLO_WORLD_H#include <QtGui/QMainWindow>#include "ui_qt_hello_world.h"class qt_hello_world : public QMainWindow{ Q_OBJECTpublic: qt_hello_world(QWidget *parent = 0, Qt::WFlags flags = 0); ~qt_hello_world();private: Ui::qt_hello_worldClass ui;};#endif // QT_HELLO_WORLD_H
#include "../../qt_hello_world.h"#if !defined(Q_MOC_OUTPUT_REVISION)#error "The header file 'qt_hello_world.h' doesn't include <QObject>."#elif Q_MOC_OUTPUT_REVISION != 59#error "This file was generated using the moc from 4.2.2. It"#error "cannot be used with the include files from this version of Qt."#error "(The moc has changed too much.)"#endifstatic const uint qt_meta_data_qt_hello_world[] = { // content: 1, // revision 0, // classname 0, 0, // classinfo 0, 0, // methods 0, 0, // properties 0, 0, // enums/sets 0 // eod};static const char qt_meta_stringdata_qt_hello_world[] = { "qt_hello_world\0"};const QMetaObject qt_hello_world::staticMetaObject = { { &QMainWindow::staticMetaObject, qt_meta_stringdata_qt_hello_world, qt_meta_data_qt_hello_world, 0 }};const QMetaObject *qt_hello_world::metaObject() const{ return &staticMetaObject;}void *qt_hello_world::qt_metacast(const char *_clname){ if (!_clname) return 0; if (!strcmp(_clname, qt_meta_stringdata_qt_hello_world)) return static_cast<void*>(const_cast<qt_hello_world*>(this)); return QMainWindow::qt_metacast(_clname);}int qt_hello_world::qt_metacall(QMetaObject::Call _c, int _id, void **_a){ _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; return _id;}
#ifndef UI_QT_HELLO_WORLD_H#define UI_QT_HELLO_WORLD_H#include <QtCore/QVariant>#include <QtGui/QAction>#include <QtGui/QApplication>#include <QtGui/QButtonGroup>#include <QtGui/QMainWindow>#include <QtGui/QMenuBar>#include <QtGui/QStatusBar>#include <QtGui/QToolBar>#include <QtGui/QWidget>class Ui_qt_hello_worldClass{public: QMenuBar *menuBar; QToolBar *mainToolBar; QWidget *centralWidget; QStatusBar *statusBar; void setupUi(QMainWindow *qt_hello_worldClass) { qt_hello_worldClass->setObjectName(QString::fromUtf8("qt_hello_worldClass")); qt_hello_worldClass->setObjectName("qt_hello_worldClass"); menuBar = new QMenuBar(qt_hello_worldClass); menuBar->setObjectName(QString::fromUtf8("menuBar")); qt_hello_worldClass->setMenuBar(menuBar); mainToolBar = new QToolBar(qt_hello_worldClass); mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); qt_hello_worldClass->addToolBar(mainToolBar); centralWidget = new QWidget(qt_hello_worldClass); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); qt_hello_worldClass->setCentralWidget(centralWidget); statusBar = new QStatusBar(qt_hello_worldClass); statusBar->setObjectName(QString::fromUtf8("statusBar")); qt_hello_worldClass->setStatusBar(statusBar); retranslateUi(qt_hello_worldClass); QSize size(600, 400); size = size.expandedTo(qt_hello_worldClass->minimumSizeHint()); qt_hello_worldClass->resize(size); QMetaObject::connectSlotsByName(qt_hello_worldClass); } // setupUi void retranslateUi(QMainWindow *qt_hello_worldClass) { qt_hello_worldClass->setWindowTitle(QApplication::translate("qt_hello_worldClass", "qt_hello_world", 0, QApplication::UnicodeUTF8)); Q_UNUSED(qt_hello_worldClass); } // retranslateUi};namespace Ui { class qt_hello_worldClass: public Ui_qt_hello_worldClass {};} // namespace Ui#endif // UI_QT_HELLO_WORLD_H
Ниже приводится текст простейшей Qt программы: 1 #include <qapplication.h> 2 #include <qlabel.h> 3 int main(int argc, char *argv[]) 4 { 5 QApplication app(argc, argv); 6 QLabel *label = new QLabel("Hello, Qt!", 0); 7 app.setMainWidget(label); 8 label->show(); 9 return app.exec();10 }
QLabel *label = new QLabel("Hello, Qt!", 0);a.setMainWidget(label);label->show();
a.setMainWidget( label );
@set PATH=path\to\qt\bin;%PATH%@set QTDIR=path\to\qt@set QMAKESPEC=win32-msvc.net
cmdvars7qmakenmake
#include <QApplication>#include <QLabel>int main( int argc, char ** argv ){ QApplication app( argc, argv ); QLabel label( "Hello, Qt!" ); label.show(); return app.exec();}
win32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QLabel::~QLabel(void)" (__imp_??1QLabel@@UAE@XZ) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWidget::show(void)" (__imp_?show@QWidget@@QAEXXZ) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::~QString(void)" (__imp_??1QString@@QAE@XZ) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QLabel::QLabel(class QString const &,class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QLabel@@QAE@ABVQString@@PAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) private: static struct QString::Data * __cdecl QString::fromAscii_helper(char const *,int)" (__imp_?fromAscii_helper@QString@@CAPAUData@1@PBDH@Z) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication@@QAE@AAHPAPADH@Z) referenced in function _mainwin32nafeg error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartupwin32nafeg fatal error LNK1120: 9 unresolved externals
win32nafeg error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBC.lib(typinfo.obj)win32nafeg error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBC.lib(typinfo.obj)win32nafeg error LNK2005: "public: __thiscall bad_cast::bad_cast(char const *)" (??0bad_cast@@QAE@PBD@Z) already defined in LIBC.lib(stdexcpt.obj)win32nafeg fatal error LNK1169: one or more multiply defined symbols foundwin32nafeg warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library