Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QIODevice cannot open .ui file from resources.
Forum Updated to NodeBB v4.3 + New Features

QIODevice cannot open .ui file from resources.

Scheduled Pinned Locked Moved Solved Qt for Python
13 Posts 3 Posters 2.0k Views 1 Watching
  • 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.
  • Z zspinelli

    I'm trying to use the FormBuilder class to load ui files from project resources I get the error:

    QIODevice::read (QFile, ":\_qtresources\ui\NewDocumentForm.ui"): device not open
    Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document.
    

    Here is what is loading it:

    class NewDocumentForm(QDialog):
        accepted = Signal()
    
        def __init__(self):
            super().__init__()
    
            form = QFile(":/_qtresources/ui/NewDocumentForm.ui")
            form.open(QFile.ReadOnly)
    
            builder = QFormBuilder()
            builder.load(form, self)
    
    

    I can only guess that it's somehow not finding the ui file since the qiodevice turns up effectively empty.

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #2

    @zspinelli
    For the error message, that comes from trying to load from a non-open file. form.open(QFile.ReadOnly) returns a boolean to indicate success/failure, and I would guess its returning False. QIODevice.errorString() might provide more information.

    Z 1 Reply Last reply
    0
    • JonBJ JonB

      @zspinelli
      For the error message, that comes from trying to load from a non-open file. form.open(QFile.ReadOnly) returns a boolean to indicate success/failure, and I would guess its returning False. QIODevice.errorString() might provide more information.

      Z Offline
      Z Offline
      zspinelli
      wrote on last edited by zspinelli
      #3

      @JonB
      The errorString gives me "No such file or directory"

      JonBJ 1 Reply Last reply
      0
      • Z zspinelli

        @JonB
        The errorString gives me "No such file or directory"

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #4

        @zspinelli
        So that's the explanation for the error! That's all I was saying.

        Z 1 Reply Last reply
        0
        • JonBJ JonB

          @zspinelli
          So that's the explanation for the error! That's all I was saying.

          Z Offline
          Z Offline
          zspinelli
          wrote on last edited by
          #5

          @JonB
          I just found something now for a tool called rcc. Is that absolutely always neccessary to use qrc stuff?
          If so, I think this might be the problem.

          JonBJ SGaistS 2 Replies Last reply
          0
          • Z zspinelli

            @JonB
            I just found something now for a tool called rcc. Is that absolutely always neccessary to use qrc stuff?
            If so, I think this might be the problem.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #6

            @zspinelli
            I assume your form resource is not at :/_qtresources/ui/NewDocumentForm.ui.

            Z 1 Reply Last reply
            0
            • JonBJ JonB

              @zspinelli
              I assume your form resource is not at :/_qtresources/ui/NewDocumentForm.ui.

              Z Offline
              Z Offline
              zspinelli
              wrote on last edited by
              #7

              @JonB
              That's the exact path to it from the top of the source directory in the file system.
              That's the path resources gave it when I added the form to the project.
              I don't know where it would be if it's not there.

              JonBJ 1 Reply Last reply
              0
              • Z zspinelli

                @JonB
                I just found something now for a tool called rcc. Is that absolutely always neccessary to use qrc stuff?
                If so, I think this might be the problem.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Hi,

                @zspinelli said in QIODevice cannot open .ui file from resources.:

                @JonB
                I just found something now for a tool called rcc. Is that absolutely always neccessary to use qrc stuff?
                If so, I think this might be the problem.

                Yes that is mandatory. Resources must be first created like in C++. See here.

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

                Z 1 Reply Last reply
                1
                • Z zspinelli

                  @JonB
                  That's the exact path to it from the top of the source directory in the file system.
                  That's the path resources gave it when I added the form to the project.
                  I don't know where it would be if it's not there.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #9

                  @zspinelli said in QIODevice cannot open .ui file from resources.:

                  That's the exact path to it from the top of the source directory in the file system.

                  That's not what you want at runtime. The :/... file path syntax is treated by Qt as referring to a resource compiled into your executable, not a real, external file. Follow @SGaist's link to achieve that.

                  Z 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Hi,

                    @zspinelli said in QIODevice cannot open .ui file from resources.:

                    @JonB
                    I just found something now for a tool called rcc. Is that absolutely always neccessary to use qrc stuff?
                    If so, I think this might be the problem.

                    Yes that is mandatory. Resources must be first created like in C++. See here.

                    Z Offline
                    Z Offline
                    zspinelli
                    wrote on last edited by
                    #10

                    @SGaist
                    The link you posted shows an example using a tool called "pyside6-rcc".
                    If that's supposed to be installed with PySide6 then for some reason I don't have it. I found this page https://stackoverflow.com/questions/22479581/cannot-use-pyside-rcc-to-compile-qrc-file mentioning some locations where it might be but it isn't present in any of them.

                    However I found another page: https://doc.qt.io/qtforpython/overviews/resources.html showing the use of the regular "rcc" which I do have as part of the Qt installation. Before I try the example shown there, should I know if one is one tool is more preferable than the other?

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

                      If the one you have supports Python code generation, then use it.

                      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
                      • Z Offline
                        Z Offline
                        zspinelli
                        wrote on last edited by
                        #12

                        I found pyside6-rcc. I'm going to note for posterity that it was found under C:\Users\<username>\AppData\Roaming\Python\Python39\Scripts

                        I ran it, got the py output as per the demonstration, and imported it. The errorString for the QFile is now "Unknown error".

                        1 Reply Last reply
                        0
                        • JonBJ JonB

                          @zspinelli said in QIODevice cannot open .ui file from resources.:

                          That's the exact path to it from the top of the source directory in the file system.

                          That's not what you want at runtime. The :/... file path syntax is treated by Qt as referring to a resource compiled into your executable, not a real, external file. Follow @SGaist's link to achieve that.

                          Z Offline
                          Z Offline
                          zspinelli
                          wrote on last edited by
                          #13

                          @JonB @SGaist
                          After lot of internet searching and fistfighting the code, I got my project back on track and got some other stuff fixed as well.
                          I had pyside6 module installed wrong and was using the wrong approach for integrating the UI form.
                          @SGaist Your recommendation for pyside6-rss led me to pyside6-uic, which was what I really needed.

                          I'm thankful to you both for tolerating and assisting me.

                          1 Reply Last reply
                          2

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved