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. Visual Studio Add-In doesn't compile `qrc` correcly
Qt 6.11 is out! See what's new in the release blog

Visual Studio Add-In doesn't compile `qrc` correcly

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.4k Views 2 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.
  • G Offline
    G Offline
    Good Guy
    wrote on last edited by
    #1

    I use Visual Studio 2013 with Qt Visual Studio Add-In 1.2.4. I used GUI to add resource (HTML file) to form qrc file. My qrc file follows:

    <RCC>
        <qresource prefix="/MainWindow">
            <file>default.html</file>
            <file>ajax-loader.gif</file>
        </qresource>
    </RCC>
    

    This file is generated by GUI, so, in ideal world, it has to work without any problems. However, when I run following code:

    QFile file(":/MainWindow/default.html");
    QByteArray dump = file.readAll();
    qDebug() << "contents: " << dump;
    qDebug() << "error status: " << file.error();
    

    I receive following message:

    
    QIODevice::read (QFile, ":\MainWindow\default.html"): device not open
    

    Is there a way to make it working?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      As the error message suggests you need to open the file first before you can readAll from it.

      1 Reply Last reply
      0
      • ValentinMicheletV Offline
        ValentinMicheletV Offline
        ValentinMichelet
        wrote on last edited by ValentinMichelet
        #3

        Here is a classic way to open a text file in read mode:

        QFile file(":/MainWindow/default.html");
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
            qDebug() << "error status: " << file.error();
            return;
        }
        
        QByteArray dump = file.readAll();
        qDebug() << "contents: " << dump;
        
        1 Reply Last reply
        0
        • G Offline
          G Offline
          Good Guy
          wrote on last edited by
          #4

          Ok, I fixed & added open method call. Now I receive following error:

          error status:  5
          

          Documentation says that this error code means "The file could not be opened."
          I put this code just to indicate broader problem: resources added from GUI doesn't work as expected. I added image and assigned it to QLabel pixmap, however, it also doesn't work. I added it also via GUI, and Qt Designer sees that image (and displays label with image correctly), but after recompilation with Visual Studio image is invisible in window. It looks like Qt Visual Studio add-in ignores this qrc file, however, it is one created automatically when I added new form, and I don't see any error messages or warnings.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Good Guy
            wrote on last edited by
            #5

            I found solution myself. After qrc file modification it is required to remove qrc file from Visual Studio project and add it back. When done, Visual Studio recompiles qrc and it is possible to read resources as files.
            Togeather with another known bug of Qt for Visual Studio (I am about the fact that it is required to comment Q_OBJECT, rebuild, and uncoment it back to force Qt for Visual Studio Add-In to compile correctly some changes in Visual Studio project), I can say that Qt for Visual Studio Add-In ignores many changes in source code and requires to recreate project periodically to affect changes. It makes problems for big projects with a lot of windows and resources.

            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