Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved use qmlRegisterType() while able to connect to another object's slots

    QML and Qt Quick
    2
    2
    97
    Loading More Posts
    • 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.
    • C
      cheetahxspeed last edited by

      I am doing interactions with C++ and Qml.

      I have a class Client, which Qml will be interact with, and a class Master.

      I want to use qmlRegisterType to expose Client into Qml. but the problem is I have to connect Client's signals to Master's slots, so the Master will response to Client's action. To be able to do the connection, I have to create Client object & Master object:

      QObject::connect(clientObj, &Client::homeChgd, masterObj, &Master::homeChanged);
      

      But when I call qmlRegisterType<Client>("com.client", 1, 0, "Client"): Client is directly passed to QML, I cannot create its object and then do the connection with Master object.

      I am now using setContextProperty() to expose the connected Client object to Qml.

      But is there a way to use qmlRegisterType() while still being able to connect to another object's slots? Or I am doing it wrong?

      Thank you very much for your help in advance.

      1 Reply Last reply Reply Quote 0
      • P
        Padlock last edited by Padlock

        I'm not 100 % sure I understood the question correctly but I don't think there's anything wrong with using setContextProperty () to expose a class to QML.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post