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. Reloading QDeclarativeView

Reloading QDeclarativeView

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.0k 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.
  • imyrvoldI Offline
    imyrvoldI Offline
    imyrvold
    wrote on last edited by
    #1

    I am developing a Qt application where i have a QDeclarativeView which I load a QML file into. I have also a QPlainTextEdit in another tab in the same application where the source of the QML lodde from the file is shown. If I change something in the QML source, I would like the QDeclarativeView to show the change.

    What I tried was to have a button which saved the change to the same file, and then call the setSource function to the declarativeView with the path to the file. But that doesn't work, the changes is not showing in the declarativeView. If I call close to the view, the same thing.

    What should I do to make the view showing the changes? The only thing that work is to quit the application, and load it upon relaunching it.

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

      I dont know if this will help, but there are a cache mechanism that can cause problems when reading
      dynamic changing files (with same name):

      My QPushButton Code:
      @
      void Dialog::on_pushButton_clicked()
      {
      QFile f( "/home/yurii/test.qml" );
      f.open( QIODevice::WriteOnly );
      if( f.isOpen() )
      {
      ui->declarativeView->engine()->clearComponentCache(); // THIS IS WHAT YOU WANT
      f.write( ui->plainTextEdit->toPlainText().toAscii().data() );
      f.close();

          ui->declarativeView->setSource( QUrl::fromLocalFile("/home/yurii/test.qml") );
      }
      

      }
      @

      QML Code inside a QPlainText:
      @
      import Qt 4.7

      Rectangle {
      width: 100
      height: 100
      Text { text: "Hello world!" }
      }
      @

      msx_br - Brazil (Netherlands)

      1 Reply Last reply
      0
      • imyrvoldI Offline
        imyrvoldI Offline
        imyrvold
        wrote on last edited by
        #3

        Thank you, clearComponentCache() worked perfect. By the way, is there a way to load a QML into QDeclarativeView directly from a QString, or is the only way to use setSource from a file?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          msx_br
          wrote on last edited by
          #4

          As in documentation:

          @
          QDeclarativeEngine engine;
          QDeclarativeComponent component(&engine);
          component.setData("import Qt 4.7\nText { text: "Hello world!" }", QUrl());
          QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(component.create());
          @

          But:

          QDeclarativeItem objects can be placed on a standard QGraphicsScene and displayed with QGraphicsView. QDeclarativeView is a QGraphicsView subclass provided as a convenience for displaying QML files, and connecting between QML and C++ Qt objects.

          msx_br - Brazil (Netherlands)

          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