QPaintDevice: Must construct a QApplication before a QPaintDevice

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • boris.smirnov@gmail.com

    QPaintDevice: Must construct a QApplication before a QPaintDevice

    Hi all,

    I have a python script that works without any problem on Windows but
    with error:

    QPaintDevice: Must construct a QApplication before a QPaintDevice

    on Linux.

    Where could be the problem?

    Thanks.
    Boris

  • Diez B. Roggisch

    #2
    Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

    boris.smirnov@g mail.com wrote:
    Hi all,
    >
    I have a python script that works without any problem on Windows but
    with error:
    >
    QPaintDevice: Must construct a QApplication before a QPaintDevice
    >
    on Linux.
    >
    Where could be the problem?
    This is the problem:

    You Must construct a QApplication before a QPaintDevice

    Diez

    Comment

    • boris.smirnov@gmail.com

      #3
      Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

      On Feb 27, 11:46 am, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
      boris.smir...@g mail.com wrote:
      Hi all,
      >
      I have a python script that works without any problem on Windows but
      with error:
      >
      QPaintDevice: Must construct a QApplication before a QPaintDevice
      >
      on Linux.
      >
      Where could be the problem?
      >
      This is the problem:
      >
      You Must construct a QApplication before a QPaintDevice
      >
      Diez
      Yes that I can deduce, but why I'm asking is why it's different on
      Windows and Linux. Should it not be platform independent?

      Comment

      • Diez B. Roggisch

        #4
        Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

        >
        Yes that I can deduce, but why I'm asking is why it's different on
        Windows and Linux. Should it not be platform independent?
        It should be. I've got no idea why it seems to work on windows but I can say
        one thing for sure: that would be an artifact that you shouldn't rely on.
        In Qt, you _always_ need a QApplication for anything. So just do as it
        requires you to do: first, construct a QApplication. Then things will work.

        Diez

        Comment

        • boris.smirnov@gmail.com

          #5
          Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

          On Feb 27, 11:56 am, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
          Yes that I can deduce, but why I'm asking is why it's different on
          Windows and Linux. Should it not be platform independent?
          >
          It should be. I've got no idea why it seems to work on windows but I can say
          one thing for sure: that would be an artifact that you shouldn't rely on.
          In Qt, you _always_ need a QApplication for anything. So just do as it
          requires you to do: first, construct a QApplication. Then things will work.
          >
          Diez
          Hmm, as I see the code, I do construct QApplication as first

          if __name__ == '__main__':
          a = QApplication (sys.argv)
          mywidget = Optimizer()
          a.setMainWidget (mywidget)
          mywidget.show()
          Update_StatusLi ne(mywidget)
          mywidget.setSta rtconfig()
          a.exec_loop ()

          Comment

          • Diez B. Roggisch

            #6
            Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

            boris.smirnov@g mail.com wrote:
            On Feb 27, 11:56 am, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
            Yes that I can deduce, but why I'm asking is why it's different on
            Windows and Linux. Should it not be platform independent?
            >>
            >It should be. I've got no idea why it seems to work on windows but I can
            >say one thing for sure: that would be an artifact that you shouldn't rely
            >on. In Qt, you _always_ need a QApplication for anything. So just do as
            >it requires you to do: first, construct a QApplication. Then things will
            >work.
            >>
            >Diez
            >
            Hmm, as I see the code, I do construct QApplication as first
            >
            if __name__ == '__main__':
            a = QApplication (sys.argv)
            mywidget = Optimizer()
            a.setMainWidget (mywidget)
            mywidget.show()
            Update_StatusLi ne(mywidget)
            mywidget.setSta rtconfig()
            a.exec_loop ()
            I don't see any QPaintDevice here. Where does that come from? You need to
            give more information, a stack trace and a reduced example exhibiting the
            behaviour.

            Diez

            Comment

            • shredwheat

              #7
              Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

              On Feb 27, 3:35 am, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
              I don't see any QPaintDevice here. Where does that come from? You need to
              give more information, a stack trace and a reduced example exhibiting the
              behaviour.
              QWidget is derived from QPaintDevice, under Qt, no widgets can be
              instantiated before the QApplication.

              This source snippet looks like it should be working. If the exception
              is happening inside Optimizer() than something really unsusual is
              happening. I suspect there is python code somewhere else happening at
              import time that is creating a widget. The exception traceback should
              show you right where that would be.

              Comment

              • boris.smirnov@gmail.com

                #8
                Re: QPaintDevice: Must construct a QApplication before a QPaintDevice


                shredwheat napísal(a):
                On Feb 27, 3:35 am, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
                I don't see any QPaintDevice here. Where does that come from? You need to
                give more information, a stack trace and a reduced example exhibiting the
                behaviour.
                >
                QWidget is derived from QPaintDevice, under Qt, no widgets can be
                instantiated before the QApplication.
                >
                This source snippet looks like it should be working. If the exception
                is happening inside Optimizer() than something really unsusual is
                happening. I suspect there is python code somewhere else happening at
                import time that is creating a widget. The exception traceback should
                show you right where that would be.
                Thanks for the reply.
                I'm not so familiar with python so could you explain me how to use and
                become the exception traceback. I've tried today to read something for
                the beginners about traceback and stack trace in the forum, but I
                haven't found something really understadable for met.
                Some piece of code for my case will help :) and I want to learn it of
                course.

                Thanks.
                Boris

                Comment

                • shredwheat

                  #9
                  Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                  When your programs stops with the error, it should also be printing a
                  stack trace. This is a list of all the functions that have been called
                  when Python had the problem.

                  You shouldn't have to do anything extra to get the stack trace.

                  Comment

                  • Phil Thompson

                    #10
                    Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                    On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
                    When your programs stops with the error, it should also be printing a
                    stack trace. This is a list of all the functions that have been called
                    when Python had the problem.
                    >
                    You shouldn't have to do anything extra to get the stack trace.
                    The error is raised in Qt and aborts immediately. It never gets back to Python
                    to generate a trace.

                    He needs to produce a short and complete test which demonstrates the problem,
                    then we can point out where the QPaintDevice is being created.

                    Phil

                    Comment

                    • boris.smirnov@gmail.com

                      #11
                      Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                      On Feb 28, 8:56 am, Phil Thompson <p...@riverbank computing.co.uk >
                      wrote:
                      On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
                      >
                      When your programs stops with the error, it should also be printing a
                      stack trace. This is a list of all the functions that have been called
                      when Python had the problem.
                      >
                      You shouldn't have to do anything extra to get the stack trace.
                      >
                      The error is raised in Qt and aborts immediately. It never gets back to Python
                      to generate a trace.
                      >
                      He needs to produce a short and complete test which demonstrates the problem,
                      then we can point out where the QPaintDevice is being created.
                      >
                      Phil
                      OK, but before I do a complete test, could anybody tell/explain me why
                      the same file is working on Windows?
                      Did anybody already meet with something similar Win vs. Linux?

                      b.

                      Comment

                      • boris.smirnov@gmail.com

                        #12
                        Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                        On Feb 28, 9:07 am, boris.smir...@g mail.com wrote:
                        On Feb 28, 8:56 am, Phil Thompson <p...@riverbank computing.co.uk >
                        wrote:
                        >
                        On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
                        >
                        When your programs stops with the error, it should also be printing a
                        stack trace. This is a list of all the functions that have been called
                        when Python had the problem.
                        >
                        You shouldn't have to do anything extra to get the stack trace.
                        >
                        The error is raised in Qt and aborts immediately. It never gets back to Python
                        to generate a trace.
                        >
                        He needs to produce a short and complete test which demonstrates the problem,
                        then we can point out where the QPaintDevice is being created.
                        >
                        Phil
                        >
                        OK, but before I do a complete test, could anybody tell/explain me why
                        the same file is working on Windows?
                        Did anybody already meet with something similar Win vs. Linux?
                        >
                        b.
                        Here is my simple script:

                        import sys
                        from qt import *
                        class Optimizer(QWidg et):
                        def __init__(self, parent = 0):
                        QWidget.__init_ _(self)
                        QGridLayout(sel f)
                        if __name__ == '__main__':
                        a = QApplication (sys.argv)
                        mywidget = Optimizer()
                        a.exec_loop()

                        This produces this:
                        python qt_script_bs_07 0228.py
                        QPaintDevice: Must construct a QApplication before a QPaintDevice

                        Any suggestions here?
                        Thanks



                        BTW: One question:
                        when I use "import qt" instead of "from qt import *" I get this error:
                        Traceback (most recent call last):
                        File "mscarideidtool _bs_070228.py", line 4, in ?
                        class Optimizer(QWidg et):
                        NameError: name 'QWidget' is not defined

                        What is the difference between "import qt" and "from qt import *" ? I
                        thought that these are the same.

                        Comment

                        • Phil Thompson

                          #13
                          Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                          On Wednesday 28 February 2007 9:00 am, boris.smirnov@g mail.com wrote:
                          On Feb 28, 9:07 am, boris.smir...@g mail.com wrote:
                          On Feb 28, 8:56 am, Phil Thompson <p...@riverbank computing.co.uk >

                          wrote:
                          On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
                          When your programs stops with the error, it should also be printing a
                          stack trace. This is a list of all the functions that have been
                          called when Python had the problem.

                          You shouldn't have to do anything extra to get the stack trace.
                          >
                          The error is raised in Qt and aborts immediately. It never gets back to
                          Python to generate a trace.
                          >
                          He needs to produce a short and complete test which demonstrates the
                          problem, then we can point out where the QPaintDevice is being created.
                          >
                          Phil
                          OK, but before I do a complete test, could anybody tell/explain me why
                          the same file is working on Windows?
                          Did anybody already meet with something similar Win vs. Linux?

                          b.
                          >
                          Here is my simple script:
                          >
                          import sys
                          from qt import *
                          class Optimizer(QWidg et):
                          def __init__(self, parent = 0):
                          QWidget.__init_ _(self)
                          QGridLayout(sel f)
                          if __name__ == '__main__':
                          a = QApplication (sys.argv)
                          mywidget = Optimizer()
                          a.exec_loop()
                          >
                          This produces this:
                          python qt_script_bs_07 0228.py
                          >
                          QPaintDevice: Must construct a QApplication before a QPaintDevice
                          >
                          Any suggestions here?
                          It works fine for me.
                          Thanks
                          >
                          >
                          >
                          BTW: One question:
                          when I use "import qt" instead of "from qt import *" I get this error:
                          Traceback (most recent call last):
                          File "mscarideidtool _bs_070228.py", line 4, in ?
                          class Optimizer(QWidg et):
                          NameError: name 'QWidget' is not defined
                          >
                          What is the difference between "import qt" and "from qt import *" ? I
                          thought that these are the same.
                          The first creates a new namespace called "qt" and imports the module's objects
                          into it. To reference those objects you have to include the namespace name.

                          The second imports the module's objects into the current namespace.

                          Phil

                          Comment

                          • boris.smirnov@gmail.com

                            #14
                            Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                            On Feb 28, 10:22 am, Phil Thompson <p...@riverbank computing.co.uk >
                            wrote:
                            On Wednesday 28 February 2007 9:00 am, boris.smir...@g mail.com wrote:
                            >
                            >
                            >
                            >
                            >
                            On Feb 28, 9:07 am, boris.smir...@g mail.com wrote:
                            On Feb 28, 8:56 am, Phil Thompson <p...@riverbank computing.co.uk >
                            >
                            wrote:
                            On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
                            When your programs stops with the error, it should also be printing a
                            stack trace. This is a list of all the functions that have been
                            called when Python had the problem.
                            >
                            You shouldn't have to do anything extra to get the stack trace.
                            >
                            The error is raised in Qt and aborts immediately. It never gets back to
                            Python to generate a trace.
                            >
                            He needs to produce a short and complete test which demonstrates the
                            problem, then we can point out where the QPaintDevice is being created.
                            >
                            Phil
                            >
                            OK, but before I do a complete test, could anybody tell/explain me why
                            the same file is working on Windows?
                            Did anybody already meet with something similar Win vs. Linux?
                            >
                            b.
                            >
                            Here is my simple script:
                            >
                            import sys
                            from qt import *
                            class Optimizer(QWidg et):
                            def __init__(self, parent = 0):
                            QWidget.__init_ _(self)
                            QGridLayout(sel f)
                            if __name__ == '__main__':
                            a = QApplication (sys.argv)
                            mywidget = Optimizer()
                            a.exec_loop()
                            >
                            This produces this:
                            python qt_script_bs_07 0228.py
                            >
                            QPaintDevice: Must construct a QApplication before a QPaintDevice
                            >
                            Any suggestions here?
                            >
                            It works fine for me.
                            >
                            Thanks
                            >
                            BTW: One question:
                            when I use "import qt" instead of "from qt import *" I get this error:
                            Traceback (most recent call last):
                            File "mscarideidtool _bs_070228.py", line 4, in ?
                            class Optimizer(QWidg et):
                            NameError: name 'QWidget' is not defined
                            >
                            What is the difference between "import qt" and "from qt import *" ? I
                            thought that these are the same.
                            >
                            The first creates a new namespace called "qt" and imports the module's objects
                            into it. To reference those objects you have to include the namespace name.
                            >
                            The second imports the module's objects into the current namespace.
                            >
                            Phil- Hide quoted text -
                            >
                            - Show quoted text -
                            OK, I have to apologize because I didn't mention that I use python
                            version 2.2.1, could it be the problem here? Bugs or something? I have
                            to use this version since it was delivered with a software that we use
                            here.

                            Comment

                            • Phil Thompson

                              #15
                              Re: QPaintDevice: Must construct a QApplication before a QPaintDevice

                              On Wednesday 28 February 2007 9:26 am, boris.smirnov@g mail.com wrote:
                              On Feb 28, 10:22 am, Phil Thompson <p...@riverbank computing.co.uk >
                              >
                              wrote:
                              On Wednesday 28 February 2007 9:00 am, boris.smir...@g mail.com wrote:
                              On Feb 28, 9:07 am, boris.smir...@g mail.com wrote:
                              On Feb 28, 8:56 am, Phil Thompson <p...@riverbank computing.co.uk >

                              wrote:
                              On Tuesday 27 February 2007 11:09 pm, shredwheat wrote:
                              When your programs stops with the error, it should also be
                              printing a stack trace. This is a list of all the functions that
                              have been called when Python had the problem.

                              You shouldn't have to do anything extra to get the stack trace.
                              >
                              The error is raised in Qt and aborts immediately. It never gets
                              back to Python to generate a trace.
                              >
                              He needs to produce a short and complete test which demonstrates
                              the problem, then we can point out where the QPaintDevice is being
                              created.
                              >
                              Phil

                              OK, but before I do a complete test, could anybody tell/explain me
                              why the same file is working on Windows?
                              Did anybody already meet with something similar Win vs. Linux?

                              b.
                              >
                              Here is my simple script:
                              >
                              import sys
                              from qt import *
                              class Optimizer(QWidg et):
                              def __init__(self, parent = 0):
                              QWidget.__init_ _(self)
                              QGridLayout(sel f)
                              if __name__ == '__main__':
                              a = QApplication (sys.argv)
                              mywidget = Optimizer()
                              a.exec_loop()
                              >
                              This produces this:
                              python qt_script_bs_07 0228.py
                              >
                              QPaintDevice: Must construct a QApplication before a QPaintDevice
                              >
                              Any suggestions here?
                              It works fine for me.
                              Thanks
                              >
                              BTW: One question:
                              when I use "import qt" instead of "from qt import *" I get this error:
                              Traceback (most recent call last):
                              File "mscarideidtool _bs_070228.py", line 4, in ?
                              class Optimizer(QWidg et):
                              NameError: name 'QWidget' is not defined
                              >
                              What is the difference between "import qt" and "from qt import *" ? I
                              thought that these are the same.
                              The first creates a new namespace called "qt" and imports the module's
                              objects into it. To reference those objects you have to include the
                              namespace name.

                              The second imports the module's objects into the current namespace.

                              Phil- Hide quoted text -

                              - Show quoted text -
                              >
                              OK, I have to apologize because I didn't mention that I use python
                              version 2.2.1, could it be the problem here? Bugs or something? I have
                              to use this version since it was delivered with a software that we use
                              here.
                              So what versions of Qt, PyQt and SIP are you using? Were these included with
                              the software you are using? If so, what is that software?

                              Phil

                              Comment

                              Working...