Results 1 to 6 of 6

Thread: QUiLoader & *.qrc files?

  1. #1
    Join Date
    Jan 2014
    Posts
    13
    Thanks
    3

    Default QUiLoader & *.qrc files?

    I would like to move away from compiling the uic and qrc files into python code through pyside-uic,.exe and pyside-rcc.exe and into loading *.ui files at runtime. I've found the QUiLoader class and that works to load the *.ui file, but one thing that is not clear to me is what mechanism loads the *.qrc file.

    From the docs:
    By including the user interface in the form's resources (myform.qrc), we ensure that it will be present at run-time:
    What is loading the myform.qrc that myform.ui is referencing?

    _chouqud_

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QUiLoader & *.qrc files?

    Nothing loads a qrc file, it is converted to C++ code and built into your program executable. In the case of Python, the equivalent code is built by pyrcc4 (or equiv) and you import that into your script.

    If you do not want to use the the resource system then the alternative is to leave the referenced files on the file system and access them directly. This is more error prone and less flexible for some purposes, but it is an option.

  3. #3
    Join Date
    Jan 2014
    Posts
    13
    Thanks
    3

    Default Re: QUiLoader & *.qrc files?

    Thank your for clearing that up. So when I use the pyside-uic, the resulting form_ui.py includes an 'import resource.py'. If I use the uiloader I need to manually include the 'import resource.py' before I invoke the UILoader.

    Regarding that quote from the docs, I'm unclear as to what benefit I gain from including the form into the resource file. For instance, at run-time I am using python to load the *.ui file through python's io operations. What does including the ui file in the resource file do differently?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QUiLoader & *.qrc files?

    Quote Originally Posted by chouqud View Post
    Thank your for clearing that up. So when I use the pyside-uic, the resulting form_ui.py includes an 'import resource.py'.
    You seem to be using resources inside your UI file, e.g. icons or something like that.

    Make sure you have removed all resources from your project before running UIC.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2014
    Posts
    13
    Thanks
    3

    Default Re: QUiLoader & *.qrc files?

    Quote Originally Posted by anda_skoa View Post
    Make sure you have removed all resources from your project before running UIC.
    Could you clarify that?

    With my python workflow, I don't have a project. I have a form.ui file made with qt designer and inside this *.ui file is a section:
    Qt Code:
    1. <resources>
    2. <include location="../../resources/resources.qrc"/>
    3. </resources>
    To copy to clipboard, switch view to plain text mode 
    And down below in a widget section for a push button, I have this entry.
    Qt Code:
    1. <property name="icon">
    2. <iconset resource="../../resources/resources.qrc">
    3. <normaloff>:/image/greenlight.png</normaloff>:/image/greenlight.png</iconset>
    4. </property>
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QUiLoader & *.qrc files?

    Quote Originally Posted by chouqud View Post
    With my python workflow, I don't have a project. I have a form.ui file made with qt designer and inside this *.ui file is a section:
    Qt Code:
    1. <resources>
    2. <include location="../../resources/resources.qrc"/>
    3. </resources>
    To copy to clipboard, switch view to plain text mode 
    Right. This triggers the resource import that you don't want. So remove it.

    Quote Originally Posted by chouqud View Post
    And down below in a widget section for a push button, I have this entry.
    Qt Code:
    1. <property name="icon">
    2. <iconset resource="../../resources/resources.qrc">
    3. <normaloff>:/image/greenlight.png</normaloff>:/image/greenlight.png</iconset>
    4. </property>
    To copy to clipboard, switch view to plain text mode 
    Either remove completely and set the icon in code or change to a file path.

    Cheers,
    _

  7. The following user says thank you to anda_skoa for this useful post:

    chouqud (20th February 2014)

Similar Threads

  1. QUiLoader and protobuf
    By waiter in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2013, 08:39
  2. QUiLoader and .qrc
    By hypnotic401 in forum Qt Programming
    Replies: 0
    Last Post: 17th September 2012, 16:27
  3. undefined reference to `QUiLoader::QUiLoader(QObject*)'
    By ashukla in forum Qt Programming
    Replies: 7
    Last Post: 7th October 2011, 18:05
  4. Advanced use of QUiLoader
    By doberkofler in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2009, 15:47
  5. Advanced use of QUiLoader
    By doberkofler in forum Newbie
    Replies: 0
    Last Post: 27th October 2009, 21:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.