Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to reload qml from cpp file?
Forum Updated to NodeBB v4.3 + New Features

How to reload qml from cpp file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 754 Views
  • 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.
  • BharathiB Offline
    BharathiB Offline
    Bharathi
    wrote on last edited by
    #1

    Need to reload the total qml file from cpp file on some time interval.I can do it in qml using loader function.How to do using cpp file??

    1 Reply Last reply
    1
    • RajeeshRaveendranR Offline
      RajeeshRaveendranR Offline
      RajeeshRaveendran
      wrote on last edited by RajeeshRaveendran
      #2

      Hi,

      Define a string type Qproperty in your cpp class and bind it to "source" property of Loader in QML.
      Now you can change the source of that Loader by changing the QProperty value from cpp.

      eg:- /// CPP code

      class XXXXX /// Register this class/object to QML using qmlRegisterType()/setConextProperty()
      {
      Q_OBJECT
      ...
      Q_PROPERTY(QString sourcePath READ sourcePath NOTIFY sourcePathChanged) //// Bind this "sourcePath" property to QML.

      	QString sourcePath() { return m_SourcePath };
      
      signals:
      	 void sourcePathChanged(); /// Notify this signal when you change the source path from CPP
      	 
      private:
      	 QString m_SourcePath; /// Update this value and emit sourcePathChanged() signal from cpp to reload QML Loader.
      

      }

      /// QML code

      Loader {
      id: myLoader
      source: XXXXX.sourcePath /// Bind the property to loader's source property.
      }

      Hope this will help you.

      Thanks,
      Rajeesh Raveendran

      1 Reply Last reply
      0
      • BharathiB Offline
        BharathiB Offline
        Bharathi
        wrote on last edited by
        #3

        @RajeeshRaveendran
        Thanks for the reply...

        In this I am not going to change the path of the qml file but going to change the entire content in the qml.Any Suggestions to solve this???

        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