Qt Quick Controls 2生成资源的方式是特殊的生成资源的方式


  • 网站研运

    0_1479887705037_桂马.jpg
    翻看Qt 5.7和Qt 5.8的Controls 2 Gallery例子,发现一个特殊的现象:

    1、Qt Creator中qml源码竟然直接显示在资源目录树下了;
    2、qml源码在Qt Creator中竟然无法打开,也不报错,只是静默忽略;

    没有办法,我只能点击“显示包含的目录”打开Qt Creator,然后一一将qml代码拖进编辑器来学习查看。
    好奇的我,还是想仔细地看看,这究竟是怎么回事?这样的程序竟然也能够编译!

    我于是找到了pro文件,下面是内容:

    TEMPLATE = app
    TARGET = gallery
    QT += quick quickcontrols2
    
    SOURCES += \
        gallery.cpp
    
    RESOURCES += \
        gallery.qml \
        qtquickcontrols2.conf \
        $$files(images/*.png) \
        $$files(images/+material/*.png) \
        $$files(pages/*.qml)
    
    target.path = $$[QT_INSTALL_EXAMPLES]/quickcontrols2/gallery
    INSTALLS += target
    
    

    注意RESOUCES的内容,发现了什么?下面竟然不跟着.qrc的文件,而是各种原始的资源!
    很奇怪哦。下面是我编译的信息:

    g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_QUICKCONTROLS2_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../gallery -I. -I../../../../5.8/gcc_64/include -I../../../../5.8/gcc_64/include/QtQuickControls2 -I../../../../5.8/gcc_64/include/QtQuick -I../../../../5.8/gcc_64/include/QtGui -I../../../../5.8/gcc_64/include/QtQml -I../../../../5.8/gcc_64/include/QtNetwork -I../../../../5.8/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I../../../../5.8/gcc_64/mkspecs/linux-g++ -o gallery.o ../gallery/gallery.cpp
    /home/jiangcaiyang/Develop/Qt5.8.0Beta/5.8/gcc_64/bin/rcc -name qmake_qmake_immediate qmake_qmake_immediate.qrc -o qrc_qmake_qmake_immediate.cpp
    g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_QUICKCONTROLS2_LIB -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I../gallery -I. -I../../../../5.8/gcc_64/include -I../../../../5.8/gcc_64/include/QtQuickControls2 -I../../../../5.8/gcc_64/include/QtQuick -I../../../../5.8/gcc_64/include/QtGui -I../../../../5.8/gcc_64/include/QtQml -I../../../../5.8/gcc_64/include/QtNetwork -I../../../../5.8/gcc_64/include/QtCore -I. -isystem /usr/include/libdrm -I../../../../5.8/gcc_64/mkspecs/linux-g++ -o qrc_qmake_qmake_immediate.o qrc_qmake_qmake_immediate.cpp
    g++ -Wl,-rpath,/home/jiangcaiyang/Develop/Qt5.8.0Beta/5.8/gcc_64/lib -Wl,-rpath-link,/home/jiangcaiyang/Develop/Qt5.8.0Beta/5.8/gcc_64/lib -o gallery gallery.o qrc_qmake_qmake_immediate.o   -L/home/jiangcaiyang/Develop/Qt5.8.0Beta/5.8/gcc_64/lib -lQt5QuickControls2 -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread 
    

    请注意哦,那就是其中有这一句:

    /home/jiangcaiyang/Develop/Qt5.8.0Beta/5.8/gcc_64/bin/rcc -name qmake_qmake_immediate qmake_qmake_immediate.qrc -o qrc_qmake_qmake_immediate.cpp
    

    竟然有这样的参数:qmake_qmake_immediate.qrc,这个是怎么出现的呢?我认为是qmake的新功能,可以直接将RESOUCES指定的内容生成.qrc文件。在以前的版本中,从来没有这么用过。目前我还没有深入源码查看是如何做到的。不过这样做的好处,就是不必新建一个qrc文件了,不过也有很大的局限,如果你想要添加到资源的文件数特别多,特别大,仍然会造成生成的qmake_qmake_immediate.qrc很大,生成速度很慢,甚至直接卡死电脑或者造成编译器堆溢出。所以这样的技巧要慎重使用哦。



  • 确实,试了下感觉有点蛋疼


 

走马观花

最近的回复

关注我们

微博
QQ群











召唤伊斯特瓦尔