diff options
| author | ruki <[email protected]> | 2020-04-07 22:36:54 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-07 09:41:28 +0800 |
| commit | 67ef2f1cc411ead96ca4ca8c537ea0d780482cd9 (patch) | |
| tree | 2b96f4a5f31a9e089ff67e8a71da44176b07038e | |
| parent | a983b0ad54b45112f777d37b6338fa5ccf10c5c6 (diff) | |
improve qt.moc rule
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot/main.cpp | 11 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot/mainwindow.cpp | 25 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot/mainwindow.h | 30 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot/mainwindow.ui | 24 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot/xmake.lua | 5 | ||||
| -rw-r--r-- | xmake/rules/qt/moc/xmake.lua | 34 |
6 files changed, 120 insertions, 9 deletions
diff --git a/tests/projects/qt/widgetapp_private_slot/main.cpp b/tests/projects/qt/widgetapp_private_slot/main.cpp new file mode 100755 index 000000000..aab39bb89 --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot/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_private_slot/mainwindow.cpp b/tests/projects/qt/widgetapp_private_slot/mainwindow.cpp new file mode 100755 index 000000000..b27141bbe --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot/mainwindow.cpp @@ -0,0 +1,25 @@ +#include "mainwindow.h"
+#include <QDebug>
+
+class MainWindowPrivate
+{
+ MainWindow *q_ptr;
+ Q_DECLARE_PUBLIC(MainWindow)
+public:
+ MainWindowPrivate(){}
+ void mainWindow_slot(){qDebug()<<"mainWindow_slot";}
+};
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent)
+{
+ d_ptr = new MainWindowPrivate;
+ d_ptr->q_ptr = this;
+}
+
+MainWindow::~MainWindow()
+{
+
+}
+
+#include "moc_mainwindow.cpp"
diff --git a/tests/projects/qt/widgetapp_private_slot/mainwindow.h b/tests/projects/qt/widgetapp_private_slot/mainwindow.h new file mode 100755 index 000000000..2ede3584b --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot/mainwindow.h @@ -0,0 +1,30 @@ +#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#if QT_VERSION >= 0x040400
+QT_BEGIN_NAMESPACE
+#endif
+
+class MainWindowPrivate;
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = nullptr);
+ ~MainWindow();
+
+private:
+ MainWindowPrivate *d_ptr;
+ Q_DECLARE_PRIVATE(MainWindow)
+ Q_DISABLE_COPY(MainWindow)
+
+ Q_PRIVATE_SLOT(d_func(), void mainWindow_slot())
+};
+#if QT_VERSION >= 0x040400
+QT_END_NAMESPACE
+#endif
+#endif // MAINWINDOW_H
diff --git a/tests/projects/qt/widgetapp_private_slot/mainwindow.ui b/tests/projects/qt/widgetapp_private_slot/mainwindow.ui new file mode 100755 index 000000000..7de574d7c --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot/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_private_slot/xmake.lua b/tests/projects/qt/widgetapp_private_slot/xmake.lua new file mode 100755 index 000000000..bae92b3cf --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot/xmake.lua @@ -0,0 +1,5 @@ +target("test")
+ add_rules("qt.widgetapp")
+ add_files("mainwindow.h")
+ add_files("*.cpp")
+ add_frameworks("QtCore", "QtGui")
diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index dc8984d43..8685643c0 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -38,8 +38,8 @@ rule("qt.moc") target:data_set("qt.moc", moc) end) - -- on build file - on_build_file(function (target, headerfile_moc, opt) + -- before build file (we need compile it first if exists Q_PRIVATE_SLOT) + before_build_file(function (target, headerfile_moc, opt) -- imports import("moc") @@ -85,14 +85,30 @@ rule("qt.moc") -- generate c++ source file for moc moc.generate(target, headerfile_moc, sourcefile_moc) - -- trace - if option.get("verbose") then - print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) - end - - -- compile c++ source file for moc + -- we need compile this moc_xxx.cpp file if exists Q_PRIVATE_SLOT, @see https://github.com/xmake-io/xmake/issues/750 dependinfo.files = {} - assert(compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags})) + local mocdata = io.readfile(headerfile_moc) + if mocdata and mocdata:find("Q_PRIVATE_SLOT") then + -- add includedirs of sourcefile_moc + target:add("includedirs", path.directory(sourcefile_moc)) + + -- remove the object file of sourcefile_moc + local objectfiles = target:objectfiles() + for idx, objectfile in ipairs(objectfiles) do + if objectfile == target:objectfile(sourcefile_moc) then + table.remove(objectfiles, idx) + break + end + end + else + -- trace + if option.get("verbose") then + print(compinst:compcmd(sourcefile_moc, objectfile, {compflags = compflags})) + end + + -- compile c++ source file for moc + assert(compinst:compile(sourcefile_moc, objectfile, {dependinfo = dependinfo, compflags = compflags})) + end -- update files and values to the dependent file dependinfo.values = depvalues |
