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. I can not read local file from qrc in qt5.11.2 + MSVC2017

I can not read local file from qrc in qt5.11.2 + MSVC2017

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.11msvc2017qfileqrc
3 Posts 2 Posters 1.2k 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.
  • M Offline
    M Offline
    Michael Rozshko
    wrote on 9 Oct 2018, 08:05 last edited by
    #1

    Hello I used Qt 5.11.2 with MSVC2017 (only for qwebengine support). I want to load some qrc, but have error (device cannot open). And watch that file url changefrom ":/files/pagespeed.html" to windows ":\files\pagespeed.html" :c So maybe I get error from thic changes. How I can disable auto replace separator fo qrc or how I can read file from qrc? I clean all and rebuild project, but it not help me.

    I use some code:

        QFile f(":/files/pagespeed.html");
        f.open(QIODevice::ReadOnly);
        QString html = QString(f.readAll());
        f.close();
    

    Qrc file

    <RCC>
        <qresource prefix="/files">
            <file>pagespeed.html</file>
        </qresource>
    </RCC>
    

    pro file

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webengine webenginewidgets
    
    TARGET = qt5-web
    TEMPLATE = app
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    CONFIG += c++11
    
    SOURCES += \
            main.cpp \
            mainwindow.cpp
    
    HEADERS += \
            mainwindow.h
    
    FORMS += \
            mainwindow.ui
    
    RESOURCES += \
        main.qrc
    

    My error
    0_1539071731128_Screenshot_16.png

    Thanks!

    J 1 Reply Last reply 9 Oct 2018, 08:12
    0
    • M Michael Rozshko
      9 Oct 2018, 08:05

      Hello I used Qt 5.11.2 with MSVC2017 (only for qwebengine support). I want to load some qrc, but have error (device cannot open). And watch that file url changefrom ":/files/pagespeed.html" to windows ":\files\pagespeed.html" :c So maybe I get error from thic changes. How I can disable auto replace separator fo qrc or how I can read file from qrc? I clean all and rebuild project, but it not help me.

      I use some code:

          QFile f(":/files/pagespeed.html");
          f.open(QIODevice::ReadOnly);
          QString html = QString(f.readAll());
          f.close();
      

      Qrc file

      <RCC>
          <qresource prefix="/files">
              <file>pagespeed.html</file>
          </qresource>
      </RCC>
      

      pro file

      QT       += core gui
      
      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webengine webenginewidgets
      
      TARGET = qt5-web
      TEMPLATE = app
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      CONFIG += c++11
      
      SOURCES += \
              main.cpp \
              mainwindow.cpp
      
      HEADERS += \
              mainwindow.h
      
      FORMS += \
              mainwindow.ui
      
      RESOURCES += \
          main.qrc
      

      My error
      0_1539071731128_Screenshot_16.png

      Thanks!

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 9 Oct 2018, 08:12 last edited by
      #2

      hi @Michael-Rozshko

      qt manages the path seperator for you (internally) if you sty with the non Windows variant :)

      Anyway, did you rerun qmake after adding the file to your Qt-Ressource file ? otherwise the file will not be packed into the binary file.

      Also you can try it with the url version of the path:

      "qrc:/files/pagespeed.html"
      

      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
      3
      • M Offline
        M Offline
        Michael Rozshko
        wrote on 9 Oct 2018, 12:24 last edited by
        #3

        You are right! It is my error, rebuild all project with full delete old directory and all work fine. Thanks for fast and good answer!

        1 Reply Last reply
        0

        3/3

        9 Oct 2018, 12:24

        • Login

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