Signalling from a thread to main window issue



  • Hi all,

    I have a gui application where I create an instance for my class. In my class (class1) I do some stuff but I also create a thread. I have some signal-slot connections from class1 to main window class, which works without any problem. However, I need to connect a signal from my thread to a signal in class1, which causes a problem apparently.

    The signal-slot between class1 and main window class is:
    @ connect(class1, SIGNAL(sgGetCurrentElement(QWebElement&)), this, SLOT(mpOnGetCurrentElement(QWebElement&)));
    @

    From the thread to class1 is:
    @ connect(insThread, SIGNAL(sgGetCurrentElement(QWebElement&)), this, SIGNAL(sgGetCurrentElement(QWebElement&)));
    @

    Whenever the second one is called, I received:

    bq. QObject::connect: Cannot queue arguments of type 'QWebElement&' (Make sure 'QWebElement&' is registered using qRegisterMetaType().)

    I have done some search about the issue and apparently I need to call qRegisterMetaType. I have learned that I need to add: @qRegisterMetaType<myElement>("myElement");@ in main. But I got the following error.

    bq. error: C2770: invalid explicit template argument(s) for 'int qRegisterMetaType(T *)'

    So, can anyone tell me how I should proceed? Thanks.


  • Moderators

    Please post the exact line you have used qRegisterMetaType in. Make sure QWebElement header is included in that file.



  • [quote author="sierdzio" date="1396724797"]Please post the exact line you have used qRegisterMetaType in. Make sure QWebElement header is included in that file.[/quote]

    Hi sierdzio,

    Here is my main function at the moment,

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    qRegisterMetaType<myElement>("myElement");
    return a.exec();
    }@


  • Moderators

    Well, no surprise it does not work, then. 'myElement'is the thing you want to register with meta object system. In your case, that is 'QWebView'... you need to put that into the registration function.



  • [quote author="sierdzio" date="1396726404"]Well, no surprise it does not work, then. 'myElement'is the thing you want to register with meta object system. In your case, that is 'QWebView'... you need to put that into the registration function. [/quote]

    Let me repeat it:

    I add the following:

    @qRegisterMetaType<QWebElement>("myElement");@

    Then I changed QWebElement with myElement in my signals-slots like for example,

    @ connect(insTargetExtractor, SIGNAL(sgGetCurrentElement(myElement&)), this, SIGNAL(sgGetCurrentElement(myElement&)));
    @

    I also added:
    @typedef QWebElement myElement;@

    But now I get

    bq. QObject::connect: Cannot queue arguments of type 'myElement&'
    (Make sure 'myElement&' is registered using qRegisterMetaType().)

    if I use:
    @qRegisterMetaType<QWebElement&>("myElement");@
    It gives again the same error that I mentioned in my first post.


  • Moderators

    Use this:
    @
    qRegisterMetaType<QWebElement>("QWebElement");
    @

    And it should work, although I am not sure about references. If not, we will try some other solution.



  • [quote author="sierdzio" date="1396777110"]Use this:
    @
    qRegisterMetaType<QWebElement>("QWebElement");
    @

    And it should work, although I am not sure about references. If not, we will try some other solution.[/quote]

    Hi sierdzio,

    The main problem is actually signalling the address of a QWebElement. I already asked what to follow ideally in the following thread:
    "Your text to link here...":http://qt-project.org/forums/viewthread/41032/
    Perhaps you could have an idea.


  • Moderators

    OK, let's jump around the threads a bit ;-)


Log in to reply
 

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