Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    qt5.11 msvc2017 qfile qrc
    2
    3
    838
    Loading More Posts
    • 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.
    • Michael Rozshko
      Michael Rozshko last edited by

      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.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @Michael Rozshko last edited by

        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

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 3
        • Michael Rozshko
          Michael Rozshko last edited by

          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 Reply Quote 0
          • First post
            Last post