Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Question about QDeclarativeComponent::setData()
Forum Updated to NodeBB v4.3 + New Features

Question about QDeclarativeComponent::setData()

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KooMikko
    wrote on last edited by
    #1

    Hello, I don't understand the documentation on QDeclarativeComponent::setData(). What does this mean: "If url is provided, it is used to set the component name and to provide a base path for items resolved by this component."?

    Am I able to create a component in c++ side based on a QML string and then create an instance of it in QML like this, MyComponent {}?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mohsen
      wrote on last edited by
      #2

      if you want to use Qt objects like QML you have to try QGraphicsView and paint your object. actually QML is script based version of QGraphics. so you can have scenes and animations like QML but with doing some code.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KooMikko
        wrote on last edited by
        #3

        Thanks mohsen for trying to help :) I did not understand your answer though. I know that I can create a QObject derived object or QDeclarativeItem derived object in c++ and then expose it to be used in QML side with qmlRegisterType. I was wondering if I can create the object like this in c++:

        QDeclarativeComponent *comp = new QDeclarativeComponent(engine);
        comp->setData("import QtQuick 1.1 \n Rectangle{ \n color: "red" \n border.color: "blue" \n border.width : 8 } ");

        ... and then instantiate this component in QML?

        I am able to instantiate it in c++ side and the rectangle will appear on screen. I was also able to put it in correct place by setting a proper parent.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved