PDA

View Full Version : QML's autogenerated signal handlers with C++ declared signals



CHerit
8th May 2013, 16:35
Hey all,

I have a program that I’m working on which uses QML. I’m relatively new to it. I’m finding some features are extremely useful and others are rather confusing. Currently, I’m trying to work with signals which are declared in my “workhorse” class (a QThread which processes data) and QML’s signal handlers that are supposed to be automatically created for them.

The problem is that my QML doesn’t seem to see them. Essentially, I’m expecting it to simply look like this:



class WorkHorse : public QThread
{
//...header code...

signals:
void myValueChanged();

//...more header code...
}

//...QML initializations...
//...QML file beginning...
Item{
//...QML code...

onMyValueChanged: someOtherItem.text = someValue;

//...More QML code...
}



Most everything else works in the interactions between QML and my workhorse but all I get is red squigglies for the “onMyValueChanged” part of my code. It hasn’t made it or can’t see it. If I type “workHorse.” and hit CTRL+Space the intellisense will show me “onMyValueChanged” as an option. If I choose it, however, “workHorse” gets redsquigglied. Deleting “workHorse” gets me red squigglies on the signal handler name.

If you guys could help me change what I need to change I’d appreciate it. Perhaps some includes in the project files or adding Q_INVOKABLE to something or rebuilding or qmake… I’m just not sure what I’m missing. Thanks.

wysota
8th May 2013, 23:44
If you want to have "onMyValueChanged" signal handler in element "Item" then signal "myValueChanged" would have been emitted by QQuickItem and not a QThread subclass. Your code construction doesn't make sense. It would be better if you provided description of what the ultimate effect that you want to achieve is and we will suggest an approach to reach your goal.

anda_skoa
9th May 2013, 16:49
If you want to have "onMyValueChanged" signal handler in element "Item" then signal "myValueChanged" would have been emitted by QQuickItem and not a QThread subclass.

Doesn't have to be a QQuickItem subclass, QThread is OK but the QML code needs an instance of that type.
E.g.something like



Item {
WorkHorse {
onMyValueChanged: ...
}
}


Cheers,
_

wysota
9th May 2013, 19:38
Doesn't have to be a QQuickItem subclass,
I meant commenting the existing code, not that you can't do it using composition.