1

(Qt 5.12.2( mingw 7.3 32-bit ) Windows 8 64-bit)

The next code works on DEBUG, but fails on RELEASE mode:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDir>
#include <QFile>
#include <QResource>
#include <QByteArray>
#include <iostream>

void exploreQrcDir( const QString& path )
{
    QDir qrcDir( ":/layouts" );
    std::cout << ":/layouts : " << std::endl;
    for ( const QString& item : qrcDir.entryList())
    {
        std::cout << item.toStdString() << std::endl;
    }

    for ( const QFileInfo& item : qrcDir.entryInfoList())
    {
        std::cout << item.absoluteFilePath().toStdString() << ";" << item.isReadable() << std::endl;
    }
}

QByteArray resourceData( const QString& path )
{
    QResource qmlFile( path );

    std::cout << "Resource is valid = " << qmlFile.isValid()
              << " , is compressed = " << qmlFile.isCompressed()
              << " , size = " << qmlFile.size() << std::endl;

    QByteArray data = (const char*)( qmlFile.data() );
    std::cout << "Resource data = " << qmlFile.data() << std::endl;
    std::cout << "ByteArray = " << data.toStdString() << std::endl;

    return data;
}

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);

    exploreQrcDir( ":/layouts" );

    const QString qmlDataSource( "qrc:/layouts/layouts.qml" );
    QQmlApplicationEngine engine;

    engine.loadData( resourceData( ":/layouts/layouts.qml" ) ); //     debug version - ok
                                                                // release version - qml window not open

//    engine.load( qmlDataSource );  // ok
//    engine.load( QUrl( qmlDataSource ) ); // ok

    return app.exec();
}

On DEBUG mode all Ok. On RLEASE mode - no errors, no app window, and app process in Task Manager task list.

What can I load QML-file from app resources in release mode ?

1 Answers1

1

Due to the Qt Quick Compiler feature which is enabled since Qt 5.11 by default, the QML files declared in QRC are compiled to binary code in release mode, and the plain text QML files are omitted.

To revert this behavior as debug build, you can either organize your QML files that the QML texts are read at run time into a QRC file:

QTQUICK_COMPILER_SKIPPED_RESOURCES += bundle_only.qrc

Or simply disable the pre-compile feature:

CONFIG -= qtquickcompiler
GPBeta
  • 116
  • 4
  • yeah i had this problem too , changed build settings - > Enable Qt Quick Compiler (checkbox) but after qt 5.12.4 i didn't had that problem – Mahdi Khalili Aug 25 '19 at 06:15
  • 1
    @MahdiKhalili Good to hear that Qt 5.12.4 has fixed it.Also note that the checkbox option depends on the version of Qt Creator. – GPBeta Aug 25 '19 at 18:12