Solved Using a Qt private class in my cmake project
-
I wanted to make my own TreeView for my QtQuick application. I do not want to use the QuickControls1 TreeView (due to limited styling possibilities), however, I would like to use its
qquicktreemodeladaptor
which is the model used by the quick controls 1 treeview. Basically, it flattens the tree into a list. The source and header files are under/Qt5.13.1/5.13.1/Src/qtquickcontrols/src/controls/Private/
. As this is a private class, how can I use it in my project? I am using Cmake, do I need to add something to find_package or to the target_link_libraries? -
@maxwell31 You're showing the path to Qt sources.
The path in a build Qt setup is like Qt/5.13.0/gcc_64/include/QtQuickControls2/5.13.0/QtQuickControls2/private/
So, you should be able to include QtQuickControls2/private/*
https://doc.qt.io/qt-5/qtquickcontrols-index.htmlBut I'm not sure whether you need to do anything in your CMake files (for qmake see https://forum.qt.io/topic/61967/add-qtgui-private-headers).
-
Hi,
True, I had the Qt sources here, and just used it there, which should not make a difference, right? At least with using this path, it did not complain that it would not find the header file. The problem I get is that when I compile the source which is using it, I getundefined reference to `QQuickTreeModelAdaptor1::QQuickTreeModelAdaptor1(QObject*)
So I guess it has to do with the librarys I link to? Are those private classes in their own .so/.dll file?
-
The file qquicktreemodeladaptor_p.h is not present in the bult Qt version, its only present in the source.
-
Alternatively it might be possible to use the TreeModelAdaptor, as is done in the QtQuick Controls 1 (see TreeView in /Qt/Qt5.13.1/5.13.1/gcc_64/qml/QtQuick/Controls/Private )
-
So for my specific problem, using the TreeModelAdaptor which is in Quick.Controls.Private works