Hi! I tried to create a library instead of a plugin, so I had to modified existing code as following:
test.pro
# there is no any change
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += ui app
# there is no any change
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += ui app
To copy to clipboard, switch view to plain text mode
app.pro
TARGET = test
TEMPLATE = app
CONFIG += debug
SOURCES += main.cpp
LIBS += E:/documents/test/app/lib/ui.dll # I realized this is the correct syntax on Windows
INCLUDEPATH += ../ui
TARGET = test
TEMPLATE = app
CONFIG += debug
SOURCES += main.cpp
LIBS += E:/documents/test/app/lib/ui.dll # I realized this is the correct syntax on Windows
INCLUDEPATH += ../ui
To copy to clipboard, switch view to plain text mode
main.cpp
// 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
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow win;
win.show();
return a.exec();
}
// 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
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow win;
win.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
ui.pro
# also I should edit this file in order to generate a library instead of a plugin
TARGET = ui
TEMPLATE = lib
DEFINES += UI_LIBRARY
CONFIG += debug
SOURCES += mainwindow.cpp
HEADERS += mainwindow.h \
ui_global.h
FORMS += mainwindow.ui
DESTDIR = ../app/lib
# also I should edit this file in order to generate a library instead of a plugin
TARGET = ui
TEMPLATE = lib
DEFINES += UI_LIBRARY
CONFIG += debug
SOURCES += mainwindow.cpp
HEADERS += mainwindow.h \
ui_global.h
FORMS += mainwindow.ui
DESTDIR = ../app/lib
To copy to clipboard, switch view to plain text mode
ui_global.h
#ifndef UI_GLOBAL_H
#define UI_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(UI_LIBRARY)
# define UISHARED_EXPORT Q_DECL_EXPORT
#else
# define UISHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // UI_GLOBAL_H
#ifndef UI_GLOBAL_H
#define UI_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(UI_LIBRARY)
# define UISHARED_EXPORT Q_DECL_EXPORT
#else
# define UISHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // UI_GLOBAL_H
To copy to clipboard, switch view to plain text mode
mainwindow.h
// OK, this is almost what QtCreator generated for me, I only added show() function in order to let Qt export this function, am I right?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_global.h"
namespace Ui {
class MainWindow;
}
class UISHARED_EXPORT MainWindow
: public QMainWindow { Q_OBJECT
public:
~MainWindow();
void show();
protected:
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
// OK, this is almost what QtCreator generated for me, I only added show() function in order to let Qt export this function, am I right?
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_global.h"
namespace Ui {
class MainWindow;
}
class UISHARED_EXPORT MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void show();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::show()
{
this->show();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::show()
{
this->show();
}
To copy to clipboard, switch view to plain text mode
OK, when I recompile this project, there is nothing wrong. But I could not run it. It says that "E:\documents\test\app\debug\test.exe exited with code -1073741819" although I have copied ui.dll to the same directory of test.exe.
Bookmarks