diff options
| author | ruki <[email protected]> | 2020-04-12 09:33:45 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-04-12 09:33:45 +0800 |
| commit | ea875a5009c391cfcfb86b9a47fbf2568a86ffd4 (patch) | |
| tree | eed2a0a7dca5e85039a3fef77c1522d5244eb8cc | |
| parent | 733213378f1057334369d3ea852b327885d191da (diff) | |
improve qt.moc
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot2/main.cpp | 11 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot2/mainwindow.cpp | 35 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot2/mainwindow.h | 32 | ||||
| -rwxr-xr-x | tests/projects/qt/widgetapp_private_slot2/mainwindow.ui | 24 | ||||
| -rw-r--r-- | tests/projects/qt/widgetapp_private_slot2/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/qt/moc/xmake.lua | 23 |
6 files changed, 124 insertions, 7 deletions
diff --git a/tests/projects/qt/widgetapp_private_slot2/main.cpp b/tests/projects/qt/widgetapp_private_slot2/main.cpp new file mode 100755 index 000000000..aab39bb89 --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot2/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_slot2/mainwindow.cpp b/tests/projects/qt/widgetapp_private_slot2/mainwindow.cpp new file mode 100755 index 000000000..aa6aee75c --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot2/mainwindow.cpp @@ -0,0 +1,35 @@ +#include "mainwindow.h"
+#include <QDebug>
+
+class MainWindowPrivate:public QObject
+{
+ Q_OBJECT
+public:
+ MainWindow *q_ptr;
+ Q_DECLARE_PUBLIC(MainWindow)
+public:
+ MainWindowPrivate(){}
+ void mainWindow_slot(){qDebug()<<"mainWindow_slot";}
+private:
+ Q_PRIVATE_SLOT(q_ptr, void test())
+};
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent)
+{
+ d_ptr = new MainWindowPrivate;
+ d_ptr->q_ptr = this;
+}
+
+MainWindow::~MainWindow()
+{
+
+}
+
+void MainWindow::test()
+{
+
+}
+
+#include "moc_mainwindow.cpp"
+#include "mainwindow.moc"
diff --git a/tests/projects/qt/widgetapp_private_slot2/mainwindow.h b/tests/projects/qt/widgetapp_private_slot2/mainwindow.h new file mode 100755 index 000000000..5350a979e --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot2/mainwindow.h @@ -0,0 +1,32 @@ +#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();
+
+public Q_SLOTS:
+ void test();
+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_slot2/mainwindow.ui b/tests/projects/qt/widgetapp_private_slot2/mainwindow.ui new file mode 100755 index 000000000..7de574d7c --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot2/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_slot2/xmake.lua b/tests/projects/qt/widgetapp_private_slot2/xmake.lua new file mode 100644 index 000000000..fdc582c30 --- /dev/null +++ b/tests/projects/qt/widgetapp_private_slot2/xmake.lua @@ -0,0 +1,6 @@ +target("test") + add_rules("qt.widgetapp") + add_files("main.cpp") + add_files("mainwindow.cpp", {rules = "qt.moc"}) + add_files("*.h") + add_files("*.ui") diff --git a/xmake/rules/qt/moc/xmake.lua b/xmake/rules/qt/moc/xmake.lua index 8685643c0..d0ed37720 100644 --- a/xmake/rules/qt/moc/xmake.lua +++ b/xmake/rules/qt/moc/xmake.lua @@ -39,7 +39,7 @@ rule("qt.moc") end) -- before build file (we need compile it first if exists Q_PRIVATE_SLOT) - before_build_file(function (target, headerfile_moc, opt) + before_build_file(function (target, sourcefile, opt) -- imports import("moc") @@ -50,7 +50,16 @@ rule("qt.moc") import("core.project.depend") -- get c++ source file for moc - local sourcefile_moc = path.join(target:autogendir(), "rules", "qt", "moc", "moc_" .. path.basename(headerfile_moc) .. ".cpp") + -- + -- add_files("mainwindow.h") -> moc_MainWindow.cpp + -- add_files("mainwindow.cpp", {rules = "qt.moc"}) -> mainwindow.moc, @see https://github.com/xmake-io/xmake/issues/750 + -- + local basename = path.basename(sourcefile) + local filename_moc = "moc_" .. basename .. ".cpp" + if sourcefile:endswith(".cpp") then + filename_moc = basename .. ".moc" + end + local sourcefile_moc = path.join(target:autogendir(), "rules", "qt", "moc", filename_moc) -- get object file local objectfile = target:objectfile(sourcefile_moc) @@ -77,17 +86,17 @@ rule("qt.moc") -- trace progress info cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", opt.progress) if option.get("verbose") then - cprint("${dim color.build.object}compiling.qt.moc %s", headerfile_moc) + cprint("${dim color.build.object}compiling.qt.moc %s", sourcefile) else - cprint("${color.build.object}compiling.qt.moc %s", headerfile_moc) + cprint("${color.build.object}compiling.qt.moc %s", sourcefile) end -- generate c++ source file for moc - moc.generate(target, headerfile_moc, sourcefile_moc) + moc.generate(target, sourcefile, sourcefile_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 = {} - local mocdata = io.readfile(headerfile_moc) + local mocdata = io.readfile(sourcefile) if mocdata and mocdata:find("Q_PRIVATE_SLOT") then -- add includedirs of sourcefile_moc target:add("includedirs", path.directory(sourcefile_moc)) @@ -112,6 +121,6 @@ rule("qt.moc") -- update files and values to the dependent file dependinfo.values = depvalues - table.insert(dependinfo.files, headerfile_moc) + table.insert(dependinfo.files, sourcefile) depend.save(dependinfo, dependfile) end) |
