Resource profiles Qt



  • In one library

    <RCC>
        <qresource prefix="/prefix1">
            <file>folder/picture.png</file>
    ...
    

    Second library

    <RCC>
        <qresource prefix="/prefix2">
            <file>folder/picture.png</file>
    ...
    

    The folders have the same names. At the same time, the annex should use:

     ":/prefix1/folder/picture.png"
    

    ":/prefix2/folder/picture.png"

    There's only a way out of the library that's blinking before.



  • A little misunderstood:

    It only works out of the library, which is set earlier.

    The right thing to do is connect resources only from the library that is lynched first, i.e. listed above on the list. pro-File.

    LIBS += -llib1 \
            -llib2
    

    This problem arises if the original files .qrc both libraries are named the same.

    Simple solution: reference files .qrc your libraries should have different names.

    This is an example where everything works as you need:

    // директория test:
    lib1/
    lib2/
    main.cpp
    test.pro
    

    // директория lib1:
    icons/
    res.pro
    icons1.qrc // < Именуем не одинаково!

    // директория lib2:
    icons/
    res.pro
    icons2.qrc // < Именуем не одинаково!

    // директория lib1/icons:
    ico1.png
    ico12.png

    // директория lib2/icons:
    ico1.png
    ico22.png

    // lib1/res.pro:
    TEMPLATE = lib
    TARGET = lib1
    RESOURCES = icons1.qrc

    // lib2/res.pro:
    TEMPLATE = lib
    TARGET = lib2
    RESOURCES = icons2.qrc

    // test.pro:
    TEMPLATE = app
    SOURCES = main.cpp
    LIBS += -llib1
    -llib2

    // icons1.qrc:
    <RCC>
    <qresource prefix="/lib1">
    <file>icons/ico1.png</file>
    <file>icons/ico12.png</file>
    </qresource>
    </RCC>

    // icons2.qrc:
    <RCC>
    <qresource prefix="/lib2">
    <file>icons/ico1.png</file>
    <file>icons/ico22.png</file>
    </qresource>
    </RCC>

    // main.cpp:
    #include <QApplication>
    #include <QIcon>
    #include <QLayout>
    #include <QPushButton>
    #include <QWidget>

    int main(int argc, char* argv[])
    {
    QApplication app(argc, argv);
    QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

    QWidget wgt;
    wgt.setLayout(new QVBoxLayout(&wgt));

    QPushButton* pb = new QPushButton(&wgt);
    pb->setIcon(QIcon(":/lib1/icons/ico1.png"));
    pb->setText(QString("lib1-ico1"));
    wgt.layout()->addWidget(pb);

    pb = new QPushButton(&wgt);
    pb->setIcon(QIcon(":/lib2/icons/ico1.png"));
    pb->setText(QString("lib2-ico1"));
    wgt.layout()->addWidget(pb);

    pb = new QPushButton(&wgt);
    pb->setIcon(QIcon(":/lib1/icons/ico12.png"));
    pb->setText(QString("lib1-ico12"));
    wgt.layout()->addWidget(pb);

    pb = new QPushButton(&wgt);
    pb->setIcon(QIcon(":/lib2/icons/ico22.png"));
    pb->setText(QString("lib2-ico22"));
    wgt.layout()->addWidget(pb);

    wgt.show();

    return app.exec();
    }




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2