Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to make .qrc file depend on .qml in Visual Studio (how to force compiling of a project when QML code is changed)?
Forum Updated to NodeBB v4.3 + New Features

How to make .qrc file depend on .qml in Visual Studio (how to force compiling of a project when QML code is changed)?

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 1 Posters 3.4k 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.
  • M Offline
    M Offline
    maxus
    wrote on 17 Apr 2013, 08:08 last edited by
    #1

    I have a C++/QML project under VS2010 with QML embedded into resource file and it works well. I get a stand-alone binary with my QML code, however when I change any QML file, VS doesn't recompile the resources. What I currently do is recompiling .qrc manually after I change .qml files and it is quite annoying.

    I know it is rather pure VS-related question on making a file depend on other files for building, but I think anyone using Qt + QML + VS will experience the same difficulties. So I would like to make a .qrc depend on all .qml and .js files (or maybe if it is easier on any file in a sub-folder), are there any simple solutions for that?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxus
      wrote on 17 Apr 2013, 14:15 last edited by
      #2

      ok, I think I come up with an acceptable solution to the problem, learned some PowerShall along the way =)

      The solution is the following:
      1. create a pre-build event that checks whether files in a certain folder are newer than the .qrc and
      2. update the .qrc modification time if such files were found
      3. force VS to execute build commands when QML-related files change

      I'm using git, so modification of only the time stamp doesn't cause any version control issues, but if you want to keep source tree read-only you can in the step 2. update some other file (that is not under the version control) and then make .qrc depend on it.

      Advantages of this methods are: you don't need to manually add dependencies to your .qrc build, and change them if you rename files and you don't need to modify .vcxproj files or change anything in Windows Registry as some other methods do.

      Here is how I do the pre-build event / time modification:


      1. Create a PowerShall file (I made one in a project directory):

      checkqml.ps1
      @param ([string]$qrcFile, [string]$qmlDir)

      write-host "Checking for updated QML dependencies..."
      write-host " QML dir: "$qmlDir
      write-host " qrc file:"$qrcFile

      $q=$(ls $qrcFile);

      foreach( $i in get-childitem $qmlDir* )
      {
      if( $i.LastWriteTime -gt $q.LastWriteTime )
      {
      $q.LastWriteTime = Get-Date;
      write-host "newer qml-related file found: "$i
      exit
      }
      }

      write-host "none found."
      @
      It takes two parameters: .qrc file and a folder path, then it checks all files in the folder and if it finds one with modification time greater than .qrc it sets the .qrc modification time to the current time, which forces VS to recompile resources.

      2. Call it from VS2010: Project->Properties->Build Events->Pre-Build Event->Command Line insert:
      powershell -file $(ProjectDir)\checkqml.ps1 $(ProjectDir)\src\gui\project.qrc $(ProjectDir)\src\gui\qml

      3. Make VS run build scrips when any of your QML changes: select all your .qml and .js in the Solution Navigator, then select Properties->General->Item Type: Custom Build Tool


      When building a solution you'll see something like:
      @PreBuildEvent:
      Checking for updated QML dependencies...
      QML dir: C:_project\src\gui\qml
      qrc file: C:_project\program.qrc
      newer qml-related file found: C:_project\src\gui\qml\globals.js
      @

      When you add new files to the qml directory you only need to set them to do a custom build (step 3.), and you don't need to do anything if you rename or delete files. The PowerShell script can also be easily adjusted to only take .qml and .js files into account or use different or recursive directories if you have any.

      1 Reply Last reply
      0

      2/2

      17 Apr 2013, 14:15

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved