Results 1 to 3 of 3

Thread: Qml fails to be parsed when referring to object.method bindings

  1. #1
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Qml fails to be parsed when referring to object.method bindings

    Hi, I hope this is the right place to ask this.
    I've got a simple Qml, which I'm trying to control using C++. What I want to happen is that when the C++ class does something, it triggers an update to the displayed elements (simple labels and rectangles) in the Qml file. This works fine on Win7, but I just cannot get it to work on embedded EC7.

    I've got a class which extends QThread and I'm using a Q_OBJECT macro and two Q_PROPERTY fields defined in the hpp, like so:
    Qt Code:
    1. Q_PROPERTY(int percent READ getPercent WRITE setPercent NOTIFY percentChanged)
    2. Q_PROPERTY(QString currentName READ getCurrentName WRITE setCurrentName NOTIFY nameChanged)
    To copy to clipboard, switch view to plain text mode 
    When I call the setCurrentName() or setPercent() methods, then it does correctly go into the moc file for signalling, so I'm pretty sure that the communication between C++ and qml is working properly.

    I give this object to the context like this:
    Qt Code:
    1. QQuickView oView;
    2. oView.rootContext()->setContextProperty("nameofmyobject", (QObject*) &object);
    3. oView.setSource(QUrl::fromLocalFile("myfile.qml"));
    4. oView.show();
    To copy to clipboard, switch view to plain text mode 
    So according to this wiki page, that should give the QML engine / viewer a reference to the object I'm using. And this works fine in Win7.

    Now the qml. If I just define simple labels like this:
    Qt Code:
    1. Text {
    2. id: percentText
    3. text: "the percent"
    4. x : 490; y : 235
    5. }
    To copy to clipboard, switch view to plain text mode 
    then the label is displayed. Obviously my getPercent() method isn't being called, because it's not referenced anywhere, but the label is shown correctly on the screen.
    Now if I change this to:
    Qt Code:
    1. Text {
    2. id: percentText
    3. text: nameofmyobject.percent
    4. x : 490; y : 235
    5. }
    To copy to clipboard, switch view to plain text mode 
    then the label isn't displayed at all. Instead, I get a wonderfully descriptive error message when the setSource() method is called: "<Unknown File>:" (apparently this is a QDeclarativeError with an empty url and empty description). And still the getPercent() method isn't called at all. I'm assuming that the parsing / binding of the qml file failed when loading it, and now that whole Text element is being completely ignored.

    The confusing thing is, that exactly the same code works fine on Win7. I have a Rectangle whose width is set by percent, a Text element showing the percent, and another Text element showing the currentName. Yet if I try to use any of these things on embedded EC7, I get one of those wondeful error messages per definition, and then that element doesn't appear at all.

    Can anyone please spot what I'm doing wrong here? Is there an important difference between Win7 and EC7 that I'm missing?
    Thank you!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qml fails to be parsed when referring to object.method bindings

    The code looks good and the fact that it works on desktop confirms that.

    Have you tried if it works with a value based context property and/or with a QObject that is not a QThread?

    Qt5.2 or earlier?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    JeremyU (4th February 2014)

  4. #3
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default [SOLVED]: Qml fails to be parsed when referring to object.method bindings

    Thanks for your reply. I've now found the problem (facepalm).
    I was certain I was using the correct (5.2) dlls, and I think that the fact that everything was compiling ok made me think I didn't need to check that - even though I suspected some kind of mismatch.
    Anyway, it turns out that I had the wrong dlls. After many many hours of confusion the answer was in the end elsewhere. Now it works fine.

    Thanks again and sorry for the noise!

Similar Threads

  1. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 06:54
  2. Dynamic object's method.
    By kalwi in forum Newbie
    Replies: 6
    Last Post: 31st July 2013, 12:23
  3. Call object method using qtscript
    By mvbhavsar in forum Newbie
    Replies: 4
    Last Post: 10th March 2013, 11:19
  4. QRegExp: get the parsed string
    By trallallero in forum Qt Programming
    Replies: 6
    Last Post: 5th April 2012, 07:18
  5. Referring to unnamed layouts from designer
    By Ben.Hines in forum Qt Tools
    Replies: 1
    Last Post: 13th April 2006, 22:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.