Problem with getting icons for applications



  • Hi! I want to get icons for all installed applications (using registry) on Windows. The problem is:

    QObject::connect: Cannot queue arguments of type 'QList<QIcon>'
    (Make sure 'QList<QIcon>' is registered using qRegisterMetaType().)
    

    How to fix it? Thanks in advance.


  • Moderators

    @Cobra91151 What are you trying to connect to what?



  • @jsulm

    I'm connecting data from Workerclass

    QThread *programsThread = new QThread();
    Worker *programsWorker = new Worker();
    programsWorker->moveToThread(programsThread);
    connect(programsWorker, &Worker::appData, this, &Test::setAppData);
    
    QList<QIcon> programIcons;
    emit appData(programIcons, displayNames, displayVersions, publishers, installLocation, uninstallLocations);
    

    and in Test class setting data in QTreeWidgetItem (QTreeWidget)

    void setAppData(QList<QIcon> icons, QStringList names, QStringList versions, QStringList publishers, QString installLocation, QStringList uninstallLocations);
    

  • Moderators

    @Cobra91151 The error message actually tells you how to fix: "Make sure 'QList<QIcon>' is registered using qRegisterMetaType()".
    See here for details: http://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType.
    It should be enough to do it for QUcon, QList should already be supported.



  • @jsulm
    So I should use this function like: qRegisterMetaType<QIcon>("QIcon");

    But where to initialize (call) it (in Worker or in Test class)? Thanks.


  • Moderators

    @Cobra91151 where you do the connection



  • @jsulm

    void Test::appProgramsThread()
    {
        qRegisterMetaType<QIcon>("QIcon");
    
        try {
            QThread *programsThread = new QThread();
            Worker *programsWorker = new Worker();
            programsWorker->moveToThread(programsThread);
            connect(programsThread, &QThread::started, programsWorker, &Test::programsData);
            connect(programsWorker, &Worker::appData, this, &Test::setAppData);
            connect(programsWorker, &Worker::noAppsData, this, &Test::allApplicationsEmptyData);
            connect(programsWorker, &Worker::appDataReady, this, &Test::setAppLogData);
            connect(programsWorker, &Worker::finished, programsThread, &QThread::quit);
            connect(programsWorker, &Worker::finished, programsWorker, &Worker::deleteLater);
            connect(programsThread, &QThread::finished, programsThread, &QThread::deleteLater);
            programsThread->start();
        } catch (...) {
            QMessageBox::critical(this, QObject::tr("Error"), QObject::tr("An error has occurred with detecting programs!"));
        }
    }
    

    Also I have tried to call it in setAppData function but it doesn't work. The same issue: QObject::connect: Cannot queue arguments of type 'QList<QIcon>' (Make sure 'QList<QIcon>' is registered using qRegisterMetaType().).


  • Moderators

    @Cobra91151 Sorry, actually you should use http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE

    Q_DECLARE_METATYPE(QIcon)
    

    But I'm wondering why it is not working out of the box for QIcon as it is Qts own class.



  • @jsulm

    I have declare it in a header file (Test.h) where I make a connection

    class Test : public QWidget
    {
        Q_OBJECT
    
     public:
        Test();  
    
     signals:
    
     public slots:
           void setAppData(QList<QIcon> icons, QStringList names, QStringList versions, QStringList publishers, QString installLocation, QStringList uninstallLocations);
    
     private:
    };
    
    Q_DECLARE_METATYPE(QIcon)
    

    The same issue is still present.



  • When I use in Test class

    class Test : public QWidget
    {
        Q_OBJECT
        Q_DECLARE_METATYPE(QIcon)
    ....
    

    I get errors:

    error: C3412: 'QMetaTypeId<QIcon>': cannot specialize template in current scope
    

    I'm using Qt 5.7.1 (Win 10).
    So, where to initialize it? Thanks.



  • @Cobra91151

    Problem solved:

    I have changed code to: qRegisterMetaType<QList<QIcon>>("QList<QIcon>"); and it works now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.