How to compile source code of QtPropertyBrowser by VS2019 correctly?
-
Thanks for your time.
I created a QT widget application by VS wizard (sln managed), then i copied source code from "Qt\5.15.0\Src\qttools\src\shared\qtpropertybrowser" to my project.
When i compiled it, errors happeded, like below:1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\x64\Debug\moc\moc_qtbuttonpropertybrowser.cpp(94,29): error C2027: use of undefined type 'QtButtonPropertyBrowserPrivate' 1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\qtpropertybrowser\qtbuttonpropertybrowser.h(47): message : see declaration of 'QtButtonPropertyBrowserPrivate' 1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\x64\Debug\moc\moc_qtbuttonpropertybrowser.cpp(95,29): error C2027: use of undefined type 'QtButtonPropertyBrowserPrivate' 1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\qtpropertybrowser\qtbuttonpropertybrowser.h(47): message : see declaration of 'QtButtonPropertyBrowserPrivate' 1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\x64\Debug\moc\moc_qtbuttonpropertybrowser.cpp(96,29): error C2027: use of undefined type 'QtButtonPropertyBrowserPrivate' 1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\qtpropertybrowser\qtbuttonpropertybrowser.h(47): message : see declaration of 'QtButtonPropertyBrowserPrivate' 1>E:\QtPropertyBrowserDemo\QtPropertyBrowserDemo\x64\Debug\moc\moc_qtpropertybrowser.cpp(377,29): error C2027: use of undefined type 'QtAbstractPropertyBrowserPrivate'
its a long error list, so i just paste some here.
I tried ervery way i can think of, like use precompiled headers, compare my project with qttools/designer, but i still cannot find the
problem.So anyone can help me out? I commited my project on GitHub, you can pull it if you wish.
Address is here: https://github.com/LiangZuoting/QtPropertyBrowserDemo
-
Hi, welcome to the forum.
The problem is your project is set up to compile the generated
moc_XXX.cpp
files for theqtpropertybrowser
headers .
In this case they are included at the end ofqtXXX.cpp
files and are not meant to be compiled separately, as they make use of the private implementation in the ccp.To fix this, in VS, select all the
qtXXX.h
files fromqtpropertybrowser
(except for theqtXXX_p.h
). Right click and select Properties.
In the property page go to Configuration Properties -> Qt Meta-Object-Compiler -> moc and set Dynamic C++ Source to Disable. This will exclude generated moc_ files from direct compilation. They will be compiled as an include in the cpp files fromqtpropertybrowser
, the way they were meant to be. -
@Chris-Kawa cooooool, you saved me! thanks a lot.
-
@Chris-Kawa , Could you help me to solve the same issue on Qt platform(QtCreator4.9.1 Based on Qt 5.12.3 (MSVC 2017, 32 bit)). How to exclude generated moc_files from direct compilation?
-
@Chris-Kawa Thank you!