Results 1 to 11 of 11

Thread: qmlscene dummydata

  1. #1
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default qmlscene dummydata

    I have this qml:

    main.qml
    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.3
    3.  
    4. Item {
    5. property alias text: t.text
    6. anchors.fill: parent
    7. Text {
    8. id: t
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    What must I put on the dummydata directory to show "Hello" on the text item?

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

    Default Re: qmlscene dummydata

    How do you use your tyoe?
    I.e where to you set the "text" property?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qmlscene dummydata

    C++ code assigns the text property, but for desiging I need to assign it to view the results.

    I put this simple sample only for simplicity, but imagine a complex design with some properties. It's difficult view the final result on qmlscene if these properties hasn't any value.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qmlscene dummydata

    What do you mean C++ assigns the property?

    Aren't binding a C++ provided value to the property in the QML code that uses your element?

    Cheers,
    _

  5. #5
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qmlscene dummydata

    The C++ code, loads the qml and assigns the property text with setProperty:
    Qt Code:
    1. item->setProperty("text", text);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qmlscene dummydata

    And why on earth would you do that?

    If you would properly use an exported object with properties, you would not only have a better setup, you could also use dummydata.

    Cheers,
    _

  7. #7
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qmlscene dummydata

    Sorry, I can't understand you.

    My question is only what must to put on dummydata to appears "Hello" on the Text item. What file must be created? t.qml? main.qml? and what contents? text: "Hello"?. I'll tried these, but doesn't work.

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

    Default Re: qmlscene dummydata

    dummydata is a way to replace externally referenced data, e.g. data exposed by C++ objects.
    You don't use any externally referenced data, so there is nothing dummydata could replace.

    If you insist on your strange approach of passing data from C++ to QML, you'll have to write a QML file that also sets the text property from outside.
    Since your filename it not suitable for usage as an element, you'll have to use a Loader or JavaScript (Qt.createComponent and createObject).

    Alternatively you could consider using the recommended C++ intergration approach with externally referenced data and using dummy data directly.

    Cheers,
    _

  9. #9
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qmlscene dummydata

    Ok, Finally I understand it, thank you very much.

    I'm using this code to show a message that is generated from C++. The actual approach is to call setProperty("text", text) like suggested on Interacting with QML Objects from C++

    Reading your answer, you consider that isn't a good approach? what approach do you suggest?

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qmlscene dummydata

    The generally recommended approach is to avoid making C++ depend on QML, but instead make QML depend on C++.

    This way the QML side, especially if it is used for UI with QtQuick, can be changed without needing to also change the C++ code.
    E.g. when UI requirements change or when designers are working on the QML side and cannot modify C++ code themselves.

    That is, the C++ side provides data and functionality and the QtQuick side decides how and when to make use of that data and when to invoke C++ functionality.

    The way to do that is to expose objects created on the C++ side to the QQmlEngine, provide data via properties on these objects and have slots and invokable methods available for the functionality (if necessary).

    Aside from avoiding dependencies from C++ toward QML, this also allows to use the data in a declarative fashion, e.g. in QML property bindings.

    So instead of getting an item from the QML object tree and hoping that is has a property of a given name, with a hopefully compatible type, the application code just sets one of more objects (instance of QObject derived classes) via setContextProperty() and lets the QML side decide where it wants to assign which value to which property.

    See http://doc.qt.io/qt-5/qtqml-cppinteg...ttributes.html

    qmlscene's dummydata mechanism can then be used to mimick or mock these exposed objects, simply by having a dummydata QML file with the same name that was used in the setContextProperty() call that exposed the actual object.

    Cheers,
    _

  11. #11
    Join Date
    Nov 2014
    Posts
    33
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: qmlscene dummydata

    Cool! I'll rewritten my code with this approach.

    Thank you very much.
    Cheers.

Similar Threads

  1. Portable qt5.4 but "no qmlscene installed"
    By manceb in forum Installation and Deployment
    Replies: 2
    Last Post: 16th April 2016, 22:01

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.