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. Problem in interaction and accessing files between the resource in the static library from application.
QtWS25 Last Chance

Problem in interaction and accessing files between the resource in the static library from application.

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 460 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.
  • R Offline
    R Offline
    rajakumar.s
    wrote on last edited by
    #1

    I have created a static lib which has two resource files images.qrc and libResource.qrc.

    libResource.qrc has the TestQtQml.qml file and images.qrc file has the test1.png .

    test1.png is accessed and displayed in the TestQtQml.qml(present in libResource.qrc) file as below.

    TestQtQml.qml
    
    import QtQuick.Window 2.12
    
    Item {
       visible: true
       width: 640
       height: 480
       // title: qsTr("TextInput Element Demo")
    
       Image {
           width: 130; height: 100
           source: "qrc:/images/test1.png" 
       }
       }
    
    

    TestQtQml.qml file is accessed in the main.cpp by using the api
    Q_INIT_RESOURCE(libResource);

    But TestQtQml.qml file is not able to find the test1.png within the static library when both are files are placed as two different resources.

    Please let us know can we use multiple resources within the static library or all the files should be embedded within a single resource file?

    Note:
    (when both TestQtQml.qml and test1.png are embedded within the single resource file, TestQtQml.qml file is able to access the test1.png)

    main.cpp
    #include "mainwindow.h"
    
    #include <QApplication>
    #include <QFile>
    #include <QDebug>
    #include <QQmlEngine>
    #include <QQmlComponent>
    #include <QQuickView>
    #include <QQmlApplicationEngine>
    #include <QQuickItem>
    #include <QObject>
    
    int main(int argc, char *argv[])
    {
        
        Q_INIT_RESOURCE(libResource);
        Q_INIT_RESOURCE(images);
    
        QApplication a(argc, argv);
        
        QQuickView view;
        view.setSource(QUrl::fromLocalFile(":/TestQtQml.qml"));
        view.show();
        return a.exec();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      As shown in the documentation, you should first create the QApplication object.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rajakumar.s
        wrote on last edited by rajakumar.s
        #3

        We have tried initialising QApplication object first.Still TestQtQml.qml file is not able to access test1.png.

        main.cpp
        
        #include "mainwindow.h"
        #include <QApplication>
        #include <QFile>
        #include <QDebug>
        #include <QQmlEngine>
        #include <QQmlComponent>
        #include <QQuickView>
        #include <QQmlApplicationEngine>
        #include <QQuickItem>
        #include <QObject>
        #include "acessqrc.h"
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            Q_INIT_RESOURCE(libResource);
            Q_INIT_RESOURCE(images);
        
            
            QQuickView view;
            view.setSource(QUrl::fromLocalFile(":/TestQtQml.qml"));
            view.show();
            view.rootObject()->setProperty("myloaderSource","qrc:/qml/TestItem.qml");
            QObject *testobject = view.rootObject();
        
            return a.exec();
        }
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Try setting a different prefix for the resources you are using.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rajakumar.s
            wrote on last edited by
            #5

            Thanks. issue is resolved after changing the prefix.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :-)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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