What's QtPrivate?
-
I'm trying to do some public-key work using QCA and Qt5. Using some of the code in one of its example files (eventhandlerdemo.cpp: (https://api.kde.org/qca/html/eventhandlerdemo_8cpp-example.html)), I got to the point to where I needed to get AskerThread to tell me that it'd finished decrypting.
I came up with this:
QObject::connect(&askerThread, &AskerThread::finished, this, &Cryptography::finishDecrypt);Trying to compile that gets me this error:
/home/me/program/cuteprogram-0.9.3/src/cryptography.cpp:354: error: cannot convert ‘const QtPrivate::FunctionPointer<void (Cryptography::*)()>::Object*’ {aka ‘const Cryptography*’} to ‘const QObject*’ In file included from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qwidget.h:45, from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qdialog.h:44, from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/qmessagebox.h:45, from /usr/include/x86_64-linux-gnu/qt5/QtWidgets/QMessageBox:1, from ../../cuteprogram-0.9.3/src/cryptography.cpp:5: /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In instantiation of ‘static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QThread::*)(QThread::QPrivateSignal); Func2 = void (Cryptography::*)(); typename QtPrivate::FunctionPointer<Func>::Object = QThread; typename QtPrivate::FunctionPointer<Func2>::Object = Cryptography]’: ../../cuteprogram-0.9.3/src/cryptography.cpp:354:21: required from here /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:265:28: error: cannot convert ‘const QtPrivate::FunctionPointer<void (Cryptography::*)()>::Object*’ {aka ‘const Cryptography*’} to ‘const QObject*’ 265 | receiver, reinterpret_cast<void **>(&slot), | ^~~~~~~~ | | | const QtPrivate::FunctionPointer<void (Cryptography::*)()>::Object* {aka const Cryptography*} /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:472:63: note: initializing argument 3 of ‘static QMetaObject::Connection QObject::connectImpl(const QObject*, void**, const QObject*, void**, QtPrivate::QSlotObjectBase*, Qt::ConnectionType, const int*, const QMetaObject*)’ 472 | const QObject *receiver, void **slotPtr, | ~~~~~~~~~~~~~~~^~~~~~~~
What's QtPrivate? I can't find it in Qt Assistant, and an Internet search only gets me more error messages like the one above. It certainly doesn't appear anywhere in my program.
Using "connect" functions always gives me trouble, but usually I can sort them out. This one's more difficult.
-
Hi @rjmx,
QtPrivate
is a namespace that encapsulate's stuff that we (as Qt users) should not need to know about.My guess, is that your
Cryptography
class either isn't derived fromQObject
, or is missing theQ_OBJECT
macro. Or that yourCryptography::finishDecrypt
function is not preceded with aslots
orQ_SLOTS
macro.Can you show us your
Cryptography
class's declaration? and theCryptography::finishDecrypt
function's signature?Cheers.
-
Hi, Paul. Thanks for the reply.
Cryptography class herewith:
#ifndef CRYPTOGRAPHY_H #define CRYPTOGRAPHY_H #include "qobjectdefs.h" #include <QStringList> enum CryptographyTypes { CRYPTOGRAPHY_TYPE_PUBLIC_KEY, CRYPTOGRAPHY_TYPE_PASSWORD }; class Cryptography { public: Cryptography(); ~Cryptography(); QStringList getSecretKeyNames(); QStringList getSecretKeyIDs(); void getKeyNames(); void encrypt(); void decrypt(); public slots: void finishDecrypt(); private: QStringList m_secretKeyNames; QStringList m_secretKeyIDs; }; #endif // CRYPTOGRAPHY_H
And Cryptography::finishDecrypt looks like this:
void Cryptography::finishDecrypt() { QMessageBox box; box.setText("'Finish' signal received."); box.exec(); }
It's just a stub for now. Once I get that working, I'll add the rest.
Thanks,
.....Ron
-
Hi @rjmx, to use signals and slots in your own class, your class must inherit
QObject
somewhere in its ancestry, and include the Q_OBJECT macro. So, you're code should look something like:class Cryptography : public QObject { Q_OBJECT public: // rest of your code as usual. ... }
Have a read of https://doc.qt.io/qt-6/signalsandslots.html#a-small-example and https://doc.qt.io/qt-6/qobject.html#Q_OBJECT.
Cheers.