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. Calling C++ method from QML before UI is shown
Forum Updated to NodeBB v4.3 + New Features

Calling C++ method from QML before UI is shown

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 294 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    I have a C++ Class called "Colors" that offers a variety of properties which hold default colors for my app. This (singleton) is used by my QML and works fine.

    I now want to change some of my default colors, so I will be calling the setters for Color's properties. However, if I do this from the Component.onCompleted for the main.qml then the entire interface will already have been drawn, and the user will see colors change onscreen.

    I could obviously do this at the C++ level, but this is a class shared amongst many apps (so I can't make it permanent). If I make a descendant of Colors then my included static function (which registers the QML type and creates my singleton instance) will have to change for the new descendant class name. So doable, but not ideal. (I suppose I could use template, but I find those ugly to maintain).

    Is there a signal my QML code can listen for that will allow me to update my Colors before the UI is drawn?

    J.HilkJ 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      @ocgltd said in Calling C++ method from QML before UI is shown:

      Component.onCompleted

      This should help as this signal will be generated when the object is created & before rendering. What is the real issue if you use Component.onCompleted signal ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • ocgltdO ocgltd

        I have a C++ Class called "Colors" that offers a variety of properties which hold default colors for my app. This (singleton) is used by my QML and works fine.

        I now want to change some of my default colors, so I will be calling the setters for Color's properties. However, if I do this from the Component.onCompleted for the main.qml then the entire interface will already have been drawn, and the user will see colors change onscreen.

        I could obviously do this at the C++ level, but this is a class shared amongst many apps (so I can't make it permanent). If I make a descendant of Colors then my included static function (which registers the QML type and creates my singleton instance) will have to change for the new descendant class name. So doable, but not ideal. (I suppose I could use template, but I find those ugly to maintain).

        Is there a signal my QML code can listen for that will allow me to update my Colors before the UI is drawn?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @ocgltd

        Colors is a singleton, so why don't you create a c++ instance/get a reference and call the default color change setter there. After that you load your main.qml. Order of execution is important here.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        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