Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What's QtPrivate?
QtWS25 Last Chance

What's QtPrivate?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 856 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rjmx
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      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 from QObject, or is missing the Q_OBJECT macro. Or that your Cryptography::finishDecrypt function is not preceded with a slots or Q_SLOTS macro.

      Can you show us your Cryptography class's declaration? and the Cryptography::finishDecrypt function's signature?

      Cheers.

      1 Reply Last reply
      2
      • R Offline
        R Offline
        rjmx
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • Paul ColbyP Offline
          Paul ColbyP Offline
          Paul Colby
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved