跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  2. Qt Development
  3. Qt for Python
  4. PyQT4 App
Forum Updated to NodeBB v4.3 + New Features

PyQT4 App

已排程 已置頂 已鎖定 已移動 Unsolved Qt for Python
42 貼文 4 Posters 10.0k 瀏覽 1 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • JonBJ JonB

    @Mitko
    The first error is correct. from PyQt5 import QtWidgets, QtCore, QtGui is good. QVBoxLayout is not in PyQt5, so the error is correct.

    Your second example is correct. QtWidgets does contain QVBoxLayout so that is good.

    Given which, it is hardly surprising that

    self.centralWidgetLayout = QtGui.QVBoxLayout(self.centralWidget)
    

    gives the error it does, is it? You know that QVBoxLayout has been moved from QtGui in Qt 4 to QtWidgets in Qt 5, don't you, because that is what you are supposed to be changing to make it work. So there's no point putting what used to work and does not work now.

    Given your second example code, there are two ways you can address QVBoxLayout:

    • QtWidgets.QVBoxLayout: This is allowed from your from PyQt5 import QtWidgets line.

    • QVBoxLayout: This is allowed from your from PyQt5.QtWidgets import (QApplication, QWidget, QVBoxLayout, ... line.

    M 離線
    M 離線
    Mitko
    寫於 最後由 編輯
    #28

    @JonB

    Hi, i'm really grateful for your help so far.

    I managed to clear that types of errors.

    But now i have different types of error:

     C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
    Traceback (most recent call last):
      File "C:/xbee-gui-master/MainForm.py", line 367, in <module>
        main()
      File "C:/xbee-gui-master/MainForm.py", line 362, in main
        bl = Block()
      File "C:/xbee-gui-master/MainForm.py", line 50, in __init__
        self.all_tab()
      File "C:/xbee-gui-master/MainForm.py", line 63, in all_tab
        self.tab_control()
      File "C:/xbee-gui-master/MainForm.py", line 160, in tab_control
        self.list_all_commands()
      File "C:/xbee-gui-master/MainForm.py", line 211, in list_all_commands
        self.connect(self.view, QtCore.SIGNAL("clicked(const QModelIndex&)"), on_item_clicked)
    AttributeError: 'Block' object has no attribute 'connect' 
    

    Can you please help me ?

    JonBJ 1 條回覆 最後回覆
    0
    • SGaistS 離線
      SGaistS 離線
      SGaist
      Lifetime Qt Champion
      寫於 最後由 編輯
      #29

      You wrote as if it was C++. That's wrong.

      With PyQt/PySide:

      source_object.name_of_signal.connect(target_object.name_of_slot)
      

      Replace source_object and target_object with suitable objects in your code.

      Note that in the project your linked to, there are several connect statements already done.

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

      1 條回覆 最後回覆
      1
      • M Mitko

        @JonB

        Hi, i'm really grateful for your help so far.

        I managed to clear that types of errors.

        But now i have different types of error:

         C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
        Traceback (most recent call last):
          File "C:/xbee-gui-master/MainForm.py", line 367, in <module>
            main()
          File "C:/xbee-gui-master/MainForm.py", line 362, in main
            bl = Block()
          File "C:/xbee-gui-master/MainForm.py", line 50, in __init__
            self.all_tab()
          File "C:/xbee-gui-master/MainForm.py", line 63, in all_tab
            self.tab_control()
          File "C:/xbee-gui-master/MainForm.py", line 160, in tab_control
            self.list_all_commands()
          File "C:/xbee-gui-master/MainForm.py", line 211, in list_all_commands
            self.connect(self.view, QtCore.SIGNAL("clicked(const QModelIndex&)"), on_item_clicked)
        AttributeError: 'Block' object has no attribute 'connect' 
        

        Can you please help me ?

        JonBJ 離線
        JonBJ 離線
        JonB
        寫於 最後由 編輯
        #30

        @Mitko

        self.connect(self.view, QtCore.SIGNAL("clicked(const QModelIndex&)"), on_item_clicked)
        

        That is the original.

        • I have never heard of self.connect().

        • I doubt that QtCore.SIGNAL("clicked(const QModelIndex&)") is acceptable, but I don't know.

        I would try

        self.view.clicked.connect(on_item_clicked)
        

        Meanwhile separately I note that the code has:

        class Block(QtGui.QMainWindow, QtGui.QTreeView):
        

        That means Block is derived from two QObjects, QMainWindow & QTreeView. This is explicitly forbidden in Qt, at least in Qt5 and/or C++. Maybe it worked in Qt4/PyQt4, but will not now in any circumstances....

        Meanwhile, I don't know why you couldn't find this for yourself but isn't https://github.com/RuslanSdk/XBee-PyQt5-V.1.0 like it says Qt5/PyQt5 and what you want?

        M 1 條回覆 最後回覆
        1
        • JonBJ JonB

          @Mitko

          self.connect(self.view, QtCore.SIGNAL("clicked(const QModelIndex&)"), on_item_clicked)
          

          That is the original.

          • I have never heard of self.connect().

          • I doubt that QtCore.SIGNAL("clicked(const QModelIndex&)") is acceptable, but I don't know.

          I would try

          self.view.clicked.connect(on_item_clicked)
          

          Meanwhile separately I note that the code has:

          class Block(QtGui.QMainWindow, QtGui.QTreeView):
          

          That means Block is derived from two QObjects, QMainWindow & QTreeView. This is explicitly forbidden in Qt, at least in Qt5 and/or C++. Maybe it worked in Qt4/PyQt4, but will not now in any circumstances....

          Meanwhile, I don't know why you couldn't find this for yourself but isn't https://github.com/RuslanSdk/XBee-PyQt5-V.1.0 like it says Qt5/PyQt5 and what you want?

          M 離線
          M 離線
          Mitko
          寫於 最後由 編輯
          #31

          @JonB

          I think i fix this:

          self.view.clicked.connect(on_item_clicked)
          

          About the "Block" error - is there some Qt5 replacement ?

          About the project you refer to - i've tried it and it can be runned, but it can't load more then one xbee modules, and i wish to establish a network with meny devices.
          I tried to contact the creator, but he don't reply.

          Meanwhile i have new errors:

           C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
          Traceback (most recent call last):
            File "C:/xbee-gui-master/MainForm.py", line 367, in <module>
              main()
            File "C:/xbee-gui-master/MainForm.py", line 362, in main
              bl = Block()
            File "C:/xbee-gui-master/MainForm.py", line 50, in __init__
              self.all_tab()
            File "C:/xbee-gui-master/MainForm.py", line 63, in all_tab
              self.tab_control()
            File "C:/xbee-gui-master/MainForm.py", line 174, in tab_control
              model = QtWidgets.QStringListModel()
          AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QStringListModel'
          

          Any help, please ?

          JonBJ 1 條回覆 最後回覆
          0
          • M Mitko

            @JonB

            I think i fix this:

            self.view.clicked.connect(on_item_clicked)
            

            About the "Block" error - is there some Qt5 replacement ?

            About the project you refer to - i've tried it and it can be runned, but it can't load more then one xbee modules, and i wish to establish a network with meny devices.
            I tried to contact the creator, but he don't reply.

            Meanwhile i have new errors:

             C:\xbee-gui-master\PyQT\Scripts\python.exe C:/xbee-gui-master/MainForm.py
            Traceback (most recent call last):
              File "C:/xbee-gui-master/MainForm.py", line 367, in <module>
                main()
              File "C:/xbee-gui-master/MainForm.py", line 362, in main
                bl = Block()
              File "C:/xbee-gui-master/MainForm.py", line 50, in __init__
                self.all_tab()
              File "C:/xbee-gui-master/MainForm.py", line 63, in all_tab
                self.tab_control()
              File "C:/xbee-gui-master/MainForm.py", line 174, in tab_control
                model = QtWidgets.QStringListModel()
            AttributeError: module 'PyQt5.QtWidgets' has no attribute 'QStringListModel'
            

            Any help, please ?

            JonBJ 離線
            JonBJ 離線
            JonB
            寫於 最後由 JonB 編輯
            #32

            @Mitko
            Now it's time for you to do the looking up. These questions are the same each time, and I don't see why I should look up the documentation for you.

            The error tells you why you can't write QtWidgets.QStringListModel(). So you need to find whatever module QStringListModel() is in.

            M 2 條回覆 最後回覆
            2
            • JonBJ JonB

              @Mitko
              Now it's time for you to do the looking up. These questions are the same each time, and I don't see why I should look up the documentation for you.

              The error tells you why you can't write QtWidgets.QStringListModel(). So you need to find whatever module QStringListModel() is in.

              M 離線
              M 離線
              Mitko
              寫於 最後由 編輯
              #33

              @JonB
              Since you saw that i'm now to this, can't you just say:

              ''QStringListModel is a QtCore class, not QtWidgets'' ?

              JonBJ jsulmJ 2 條回覆 最後回覆
              0
              • JonBJ JonB

                @Mitko
                Now it's time for you to do the looking up. These questions are the same each time, and I don't see why I should look up the documentation for you.

                The error tells you why you can't write QtWidgets.QStringListModel(). So you need to find whatever module QStringListModel() is in.

                M 離線
                M 離線
                Mitko
                寫於 最後由 編輯
                #34

                @JonB
                Any way... I run it.

                But when i try to make test, it can't obtain xbee modules, and when i hit the ''compound'' button, the app don't respond.

                Xbee-gui error.jpg

                1 條回覆 最後回覆
                0
                • M Mitko

                  @JonB
                  Since you saw that i'm now to this, can't you just say:

                  ''QStringListModel is a QtCore class, not QtWidgets'' ?

                  JonBJ 離線
                  JonBJ 離線
                  JonB
                  寫於 最後由 JonB 編輯
                  #35

                  @Mitko said in PyQT4 App:

                  Since you saw that i'm now to this, can't you just say:
                  ''QStringListModel is a QtCore class, not QtWidgets'' ?

                  Since you saw how much help/time I've spent on this for you, given that I told you I am no Qt expert and it's just a question of you making the effort to actually just Google instead of me making that effort for your program, can't you just say:
                  "Thanks for all the help so far, you're quite right I can type that into Google, no reason why should do that for me"
                  ?

                  So your attitude is the more I help the more I should help, to save you effort, else I'm not doing the job I owe you? Find someone else.

                  M 1 條回覆 最後回覆
                  1
                  • JonBJ JonB

                    @Mitko said in PyQT4 App:

                    Since you saw that i'm now to this, can't you just say:
                    ''QStringListModel is a QtCore class, not QtWidgets'' ?

                    Since you saw how much help/time I've spent on this for you, given that I told you I am no Qt expert and it's just a question of you making the effort to actually just Google instead of me making that effort for your program, can't you just say:
                    "Thanks for all the help so far, you're quite right I can type that into Google, no reason why should do that for me"
                    ?

                    So your attitude is the more I help the more I should help, to save you effort, else I'm not doing the job I owe you? Find someone else.

                    M 離線
                    M 離線
                    Mitko
                    寫於 最後由 編輯
                    #36

                    @JonB

                    I already said:
                    ''Hi, i'm really grateful for your help so far''.

                    About the effort:
                    I don't have problems with efforts, i just don't understand the QT, and just needed little help for better understanding the details.

                    And again- Thank you all !!!

                    SGaistS 1 條回覆 最後回覆
                    0
                    • M Mitko

                      @JonB

                      I already said:
                      ''Hi, i'm really grateful for your help so far''.

                      About the effort:
                      I don't have problems with efforts, i just don't understand the QT, and just needed little help for better understanding the details.

                      And again- Thank you all !!!

                      SGaistS 離線
                      SGaistS 離線
                      SGaist
                      Lifetime Qt Champion
                      寫於 最後由 編輯
                      #37

                      @Mitko You do realize that in in the case of the "has no attribute XXX" error, several people explained to you that some classes have moved from one module to another and that the information can be found on the class documentation. Hence the only thing you have to do with that error is go to the class documentation to get the module you need to import that class from.

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

                      M 1 條回覆 最後回覆
                      1
                      • SGaistS SGaist

                        @Mitko You do realize that in in the case of the "has no attribute XXX" error, several people explained to you that some classes have moved from one module to another and that the information can be found on the class documentation. Hence the only thing you have to do with that error is go to the class documentation to get the module you need to import that class from.

                        M 離線
                        M 離線
                        Mitko
                        寫於 最後由 編輯
                        #38

                        @SGaist
                        Like i said, i'm not familiar enough with Qt, in order to understand this details.

                        JonBJ 1 條回覆 最後回覆
                        0
                        • M Mitko

                          @SGaist
                          Like i said, i'm not familiar enough with Qt, in order to understand this details.

                          JonBJ 離線
                          JonBJ 離線
                          JonB
                          寫於 最後由 編輯
                          #39

                          @Mitko
                          For the record, these are purely Python errors. You would get the same errors in the same circumstances in Python with any module, nothing special about Qt. So this is an issue of Python knowledge/understanding.

                          1 條回覆 最後回覆
                          0
                          • M Mitko

                            @JonB
                            Since you saw that i'm now to this, can't you just say:

                            ''QStringListModel is a QtCore class, not QtWidgets'' ?

                            jsulmJ 離線
                            jsulmJ 離線
                            jsulm
                            Lifetime Qt Champion
                            寫於 最後由 jsulm 編輯
                            #40

                            @Mitko said in PyQT4 App:

                            Since you saw that i'm now to this, can't you just say:

                            And can't you find it out by yourself?
                            You already asked these kind of questions and were told how to find this information.
                            Why should others do the research for you all the time?

                            The fact that you are a beginner doesn't mean that you should not learn how to find needed information after you were told several times how to do so...

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            M 1 條回覆 最後回覆
                            1
                            • jsulmJ jsulm

                              @Mitko said in PyQT4 App:

                              Since you saw that i'm now to this, can't you just say:

                              And can't you find it out by yourself?
                              You already asked these kind of questions and were told how to find this information.
                              Why should others do the research for you all the time?

                              The fact that you are a beginner doesn't mean that you should not learn how to find needed information after you were told several times how to do so...

                              M 離線
                              M 離線
                              Mitko
                              寫於 最後由 編輯
                              #41

                              @jsulm

                              As I said:
                              I still don't understand enough the details.

                              1 條回覆 最後回覆
                              0
                              • SGaistS 離線
                                SGaistS 離線
                                SGaist
                                Lifetime Qt Champion
                                寫於 最後由 編輯
                                #42

                                As we suggested: read the class documentation

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

                                1 條回覆 最後回覆
                                1

                                • 登入

                                • Login or register to search.
                                • 第一個貼文
                                  最後的貼文
                                0
                                • 版面
                                • 最新
                                • 標籤
                                • 熱門
                                • 使用者
                                • 群組
                                • 搜尋
                                • Get Qt Extensions
                                • Unsolved