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



  • 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!


  • Moderators

    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"
    


  • 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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.