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. QDeclarativeView problem
Forum Updated to NodeBB v4.3 + New Features

QDeclarativeView problem

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.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.
  • H Offline
    H Offline
    huluyige
    wrote on last edited by
    #1

    Hi everyone,

    in main.cpp

    @QDeclarativeView view;

    view.rootContext()->setContextProperty("numFromCPP", QVariant("3"));
    view.setSource(QUrl("/mainPage.qml"));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    view.showFullScreen()@

    the property value is from another thread (another signal will send the value).

    The problem is: I want to set property when the value is available . But setContextProperty is not a slot, i can not connect it to the signal.

    or, do you have some solutions? for example, is there any ways that i can update the loaded qml's property?

    I am really confused with the problem. Thank you very much

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What you could do, is create a simple QObject class that works as a proxy for the property value. Create a property, and make the setter method a slot while you emit a signal when the value changes (see Q_PROPERTY). Connect the slot to the signal from the other thread, and then expose the QObject to your QML using a new QDeclarativeContext and it's setContextObject method.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        huluyige
        wrote on last edited by
        #3

        Hi,

        Thank you very much.

        i have tried your solution. what i can't understand is this sentence

        "expose the QObject to your QML using a new QDeclarativeContext and it’s setContextObject method"

        what i want to change in the mainPage.qml is just a property, not an QObject.

        Here is the code, i dont know how to do it for the next step
        @ Proxy proxy;
        QObject::connect(&parserDirects,SIGNAL(allFinished (int)),&proxy,SLOT(setNumber(int)));

        QDeclarativeView view;
        
        view.rootContext()->setContextProperty("numFromCPP", QVariant("3"));
        view.setSource(QUrl("/home/zhiheng/Projets/LequipeOVI-build-simulator/qml/LequipeOVI/mainPage.qml"));
        view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
        view.showFullScreen();@
        

        [quote author="Andre" date="1299243800"]What you could do, is create a simple QObject class that works as a proxy for the property value. Create a property, and make the setter method a slot while you emit a signal when the value changes (see Q_PROPERTY). Connect the slot to the signal from the other thread, and then expose the QObject to your QML using a new QDeclarativeContext and it's setContextObject method.[/quote]

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          [quote author="huluyige" date="1299248555"]what i want to change in the mainPage.qml is just a property, not an QObject.
          [/quote]

          The point I was trying to make, is that you could make a QObject in order to expose your value to the QML. I understand that you currently don't have a QObject, but that is exactly your problem I think. A QObject can have a slot (you said you need one to connect to a signal in your value-providing thread), and it can be exposed to QML if you give it properties. Sounds like the bridge you need to me...

          1 Reply Last reply
          0
          • H Offline
            H Offline
            huluyige
            wrote on last edited by
            #5

            Thank you very much.

            Now, I totally understand your point.

            By doing this, I have others problems (i am new to QT):

            1. "A new QDeclarativeContext " why i have to use a NEW QDeclarativeContext.

            2. the method "setContextObject" is to set another object to the Context ? if it is yes, how can i connect the new object to the former objet(apprarently, it's the object of mainPage.qml)

            Thanks

            [quote author="Andre" date="1299250351"][quote author="huluyige" date="1299248555"]what i want to change in the mainPage.qml is just a property, not an QObject.
            [/quote]

            The point I was trying to make, is that you could make a QObject in order to expose your value to the QML. I understand that you currently don't have a QObject, but that is exactly your problem I think. A QObject can have a slot (you said you need one to connect to a signal in your value-providing thread), and it can be exposed to QML if you give it properties. Sounds like the bridge you need to me...[/quote]

            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