[Qt-interest] problem about creating library
程梁
chengliang.soft at gmail.com
Sun May 2 03:21:34 CEST 2010
Hi, all! I tried to create a library with Qt but I can't run. There is no
compile error although.
There is my code:
/ --- test.pro
|
ui ---- ui.pro
| | -- mainwindow.h
| | -- mainwindow.cpp
| | -- ui_global.h
|
app ----- app.pro
| --- main.cpp
test.pro
1. TEMPLATE = subdirs
2. CONFIG += ordered
3. SUBDIRS += ui app
app.pro
1. TARGET = test
2. TEMPLATE = app
3. CONFIG += debug
4. SOURCES += main.cpp
5. LIBS += E:/documents/test/app/lib/ui.dll
6. INCLUDEPATH += ../ui
main.cpp
1. // Since this is a library, I think I should use it just like QtGui
and so on, so I include necessary head files and create an instance as usual
2. #include <QtGui/QApplication>
3. #include "mainwindow.h"
4.
5. int main(int argc, char *argv[])
6. {
7. QApplication <http://doc.qt.nokia.com/latest/qapplication.html> a(argc,
argv);
8. MainWindow win;
9. win.show();
10. return a.exec();
11. }
ui.pro
1. # also I should edit this file in order to generate a library instead
of a plugin
2. TARGET = ui
3. TEMPLATE = lib
4. DEFINES += UI_LIBRARY
5. CONFIG += debug
6. SOURCES += mainwindow.cpp
7. HEADERS += mainwindow.h \
8. ui_global.h
9. FORMS += mainwindow.ui
10. DESTDIR = ../app/lib
ui_global.h
1. #ifndef UI_GLOBAL_H
2. #define UI_GLOBAL_H
3.
4. #include <QtCore/qglobal.h>
5.
6. #if defined(UI_LIBRARY)
7. # define UISHARED_EXPORT Q_DECL_EXPORT
8. #else
9. # define UISHARED_EXPORT Q_DECL_IMPORT
10. #endif
11.
12. #endif // UI_GLOBAL_H
mainwindow.h
1. // OK, this is almost what QtCreator generated for me
2. #ifndef MAINWINDOW_H
3. #define MAINWINDOW_H
4.
5. #include <QMainWindow>
6. #include "ui_global.h"
7.
8. namespace Ui {
9. class MainWindow;
10. }
11.
12. class UISHARED_EXPORT MainWindow : public
QMainWindow<http://doc.qt.nokia.com/latest/qmainwindow.html>
{
13. Q_OBJECT
14. public:
15. MainWindow(QWidget
<http://doc.qt.nokia.com/latest/qwidget.html> *parent
= 0);
16. ~MainWindow();
17. protected:
18. void changeEvent(QEvent <http://doc.qt.nokia.com/latest/qevent.html>
*e);
19. private:
20. Ui::MainWindow *ui;
21. };
22.
23. #endif // MAINWINDOW_H
I ignored cpp and ui files since they are all just like what QtCreator
generated for me.
I tried to check test.exe by Dependency Walker and it shows the ui.dll. Then
I copied
this dll to the same directory of test.exe neither I run from QtCreator nor
double click
can run it. In QtCreator it gives me exit code -1073741819
Some one told me I should have a ui.lib with ui.dll but I really don't. What
should I do?
--
Cheng Liang
from: chengliang.soft at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100502/d6f2f62f/attachment.html
More information about the Qt-interest-old
mailing list