summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-04-18 00:20:54 +0800
committerruki <[email protected]>2018-04-17 20:05:25 +0800
commitde0b81ca10f04ae93e6a68278ec7f888acd0498d (patch)
tree5d1d12cf0e5a0f810ac309286a7f80d698036209
parente9df357185b4ed02e230a11bfe76ad7dcf3a5376 (diff)
add qt widget app test
-rw-r--r--tests/projects/qt_widgetapp/src/main.cpp11
-rw-r--r--tests/projects/qt_widgetapp/src/mainwindow.cpp14
-rw-r--r--tests/projects/qt_widgetapp/src/mainwindow.h22
-rw-r--r--tests/projects/qt_widgetapp/src/mainwindow.ui24
-rw-r--r--tests/projects/qt_widgetapp/xmake.lua17
-rw-r--r--xmake/core/project/target.lua2
-rw-r--r--xmake/rules/qt/xmake.lua19
7 files changed, 105 insertions, 4 deletions
diff --git a/tests/projects/qt_widgetapp/src/main.cpp b/tests/projects/qt_widgetapp/src/main.cpp
new file mode 100644
index 000000000..b48f94ec8
--- /dev/null
+++ b/tests/projects/qt_widgetapp/src/main.cpp
@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/projects/qt_widgetapp/src/mainwindow.cpp b/tests/projects/qt_widgetapp/src/mainwindow.cpp
new file mode 100644
index 000000000..49d64fce7
--- /dev/null
+++ b/tests/projects/qt_widgetapp/src/mainwindow.cpp
@@ -0,0 +1,14 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
diff --git a/tests/projects/qt_widgetapp/src/mainwindow.h b/tests/projects/qt_widgetapp/src/mainwindow.h
new file mode 100644
index 000000000..a3948a917
--- /dev/null
+++ b/tests/projects/qt_widgetapp/src/mainwindow.h
@@ -0,0 +1,22 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+};
+
+#endif // MAINWINDOW_H
diff --git a/tests/projects/qt_widgetapp/src/mainwindow.ui b/tests/projects/qt_widgetapp/src/mainwindow.ui
new file mode 100644
index 000000000..6050363fa
--- /dev/null
+++ b/tests/projects/qt_widgetapp/src/mainwindow.ui
@@ -0,0 +1,24 @@
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>MainWindow</string>
+ </property>
+ <widget class="QMenuBar" name="menuBar" />
+ <widget class="QToolBar" name="mainToolBar" />
+ <widget class="QWidget" name="centralWidget" />
+ <widget class="QStatusBar" name="statusBar" />
+ </widget>
+ <layoutDefault spacing="6" margin="11" />
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/projects/qt_widgetapp/xmake.lua b/tests/projects/qt_widgetapp/xmake.lua
new file mode 100644
index 000000000..0ffe26ce1
--- /dev/null
+++ b/tests/projects/qt_widgetapp/xmake.lua
@@ -0,0 +1,17 @@
+
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
+
+-- add target
+target("qt_demo")
+
+ -- add rules
+ add_rules("qt.widgetapp")
+
+ -- add headers
+ add_headers("src/*.h")
+
+ -- add files
+ add_files("src/*.cpp")
+ add_files("src/mainwindow.ui")
+
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 1cea91ed2..3031cb7a9 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -175,7 +175,7 @@ end
-- get user data
function target:data(name)
- return self._DATA[name]
+ return self._DATA and self._DATA[name] or nil
end
-- set user data
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index a1ec4957d..189cf1f1a 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -28,7 +28,9 @@ rule("qt.env")
-- on load
on_load(function (target)
import("detect.sdks.find_qt")
- target:data_set("qt", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!"))
+ if not target:data("qt") then
+ target:data_set("qt", assert(find_qt(nil, {verbose = true}), "Qt SDK not found!"))
+ end
end)
-- define rule: qt static library
@@ -92,7 +94,7 @@ rule("qt.qrc")
assert(rcc and os.isexec(rcc), "rcc not found!")
-- save rcc
- target:data_set("rcc", rcc)
+ target:data_set("qt.rcc", rcc)
end)
-- on build file
@@ -104,7 +106,7 @@ rule("qt.qrc")
import("core.tool.compiler")
-- get rcc
- local rcc = target:data("rcc")
+ local rcc = target:data("qt.rcc")
-- get c++ source file for qrc
local sourcefile_cpp = path.join(config.buildir(), ".qt", "qrc", target:name(), path.basename(sourcefile_qrc) .. ".cpp")
@@ -134,6 +136,17 @@ rule("qt.qrc")
-- add objectfile
table.insert(target:objectfiles(), objectfile)
+
+ -- add clean files
+ target:data_set("qt.qrc.cleanfiles", {sourcefile_cpp, objectfile})
+ end)
+
+ -- clean files
+ after_clean(function (target)
+ for _, file in ipairs(target:data("qt.qrc.cleanfiles")) do
+ os.rm(file)
+ end
+ target:data_set("qt.qrc.cleanfiles", nil)
end)
-- define rule: qt quick application