无法启动使用Qt4和Python 3.4创建的gui应用程序,并且无法找到QStringList类

时间:2015-11-14 11:42:33

标签: python-3.x qt4 pyqt4

我在Qt4中创建了GUI Design,你可以看到Design here

与pyuic4相比,我将设计转换为GuiVezba2DialogQt4.py。 在这里,您可以看到该类的代码:

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
    return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(554, 407)
        self.horizontalLayoutWidget = QtGui.QWidget(Dialog)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(40, 10, 411, 61))
    self.horizontalLayoutWidget.setObjectName(_fromUtf8("horizontalLayoutWidget"))
    self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
    self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
    self.pushButton = QtGui.QPushButton(self.horizontalLayoutWidget)
    self.pushButton.setObjectName(_fromUtf8("pushButton"))
    self.horizontalLayout.addWidget(self.pushButton)
    self.pushButton_2 = QtGui.QPushButton(self.horizontalLayoutWidget)
    self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
    self.horizontalLayout.addWidget(self.pushButton_2)
    self.pushButton_3 = QtGui.QPushButton(self.horizontalLayoutWidget)
    self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
    self.horizontalLayout.addWidget(self.pushButton_3)
    self.horizontalLayoutWidget_2 = QtGui.QWidget(Dialog)
    self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(40, 70, 411, 41))
             self.horizontalLayoutWidget_2.setObjectName(_fromUtf8("horizontalLayoutWidget_2"))
    self.horizontalLayout_2 = QtGui.QHBoxLayout(self.horizontalLayoutWidget_2)
    self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
    self.label_20 = QtGui.QLabel(self.horizontalLayoutWidget_2)
    self.label_20.setObjectName(_fromUtf8("label_20"))
    self.horizontalLayout_2.addWidget(self.label_20)
    self.label_21 = QtGui.QLabel(self.horizontalLayoutWidget_2)
    self.label_21.setObjectName(_fromUtf8("label_21"))
    self.horizontalLayout_2.addWidget(self.label_21)
    self.label_22 = QtGui.QLabel(self.horizontalLayoutWidget_2)
    self.label_22.setObjectName(_fromUtf8("label_22"))
    self.horizontalLayout_2.addWidget(self.label_22)
    self.groupBox = QtGui.QGroupBox(Dialog)
    self.groupBox.setGeometry(QtCore.QRect(10, 130, 291, 171))
    self.groupBox.setObjectName(_fromUtf8("groupBox"))
    self.label = QtGui.QLabel(self.groupBox)
    self.label.setGeometry(QtCore.QRect(10, 20, 91, 21))
    self.label.setObjectName(_fromUtf8("label"))
    self.lineEdit = QtGui.QLineEdit(self.groupBox)
    self.lineEdit.setGeometry(QtCore.QRect(170, 20, 51, 20))
    self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
    self.pushButton_4 = QtGui.QPushButton(self.groupBox)
    self.pushButton_4.setGeometry(QtCore.QRect(160, 130, 75, 23))
    self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
    self.label_4 = QtGui.QLabel(self.groupBox)
    self.label_4.setGeometry(QtCore.QRect(170, 70, 111, 16))
    self.label_4.setObjectName(_fromUtf8("label_4"))
    self.label_9 = QtGui.QLabel(self.groupBox)
    self.label_9.setGeometry(QtCore.QRect(170, 110, 111, 16))
    self.label_9.setObjectName(_fromUtf8("label_9"))
    self.label_3 = QtGui.QLabel(self.groupBox)
    self.label_3.setGeometry(QtCore.QRect(170, 50, 111, 16))
    self.label_3.setObjectName(_fromUtf8("label_3"))
    self.label_5 = QtGui.QLabel(self.groupBox)
    self.label_5.setGeometry(QtCore.QRect(170, 90, 111, 16))
    self.label_5.setObjectName(_fromUtf8("label_5"))
    self.label_2 = QtGui.QLabel(self.groupBox)
    self.label_2.setGeometry(QtCore.QRect(10, 50, 131, 16))
    self.label_2.setObjectName(_fromUtf8("label_2"))
    self.label_12 = QtGui.QLabel(self.groupBox)
    self.label_12.setGeometry(QtCore.QRect(10, 70, 131, 16))
    self.label_12.setObjectName(_fromUtf8("label_12"))
    self.label_13 = QtGui.QLabel(self.groupBox)
    self.label_13.setGeometry(QtCore.QRect(10, 90, 131, 16))
    self.label_13.setObjectName(_fromUtf8("label_13"))
    self.label_14 = QtGui.QLabel(self.groupBox)
    self.label_14.setGeometry(QtCore.QRect(10, 110, 131, 16))
    self.label_14.setObjectName(_fromUtf8("label_14"))
    self.label_15 = QtGui.QLabel(self.groupBox)
    self.label_15.setGeometry(QtCore.QRect(10, 130, 131, 16))
    self.label_15.setObjectName(_fromUtf8("label_15"))
    self.groupBox_2 = QtGui.QGroupBox(Dialog)
    self.groupBox_2.setGeometry(QtCore.QRect(310, 130, 241, 171))
    self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
    self.label_10 = QtGui.QLabel(self.groupBox_2)
    self.label_10.setGeometry(QtCore.QRect(10, 30, 71, 16))
    self.label_10.setObjectName(_fromUtf8("label_10"))
    self.lineEdit_2 = QtGui.QLineEdit(self.groupBox_2)
    self.lineEdit_2.setGeometry(QtCore.QRect(140, 30, 71, 20))
    self.lineEdit_2.setInputMask(_fromUtf8(""))
    self.lineEdit_2.setText(_fromUtf8(""))
    self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))
    self.label_6 = QtGui.QLabel(self.groupBox_2)
    self.label_6.setGeometry(QtCore.QRect(140, 60, 61, 16))
    self.label_6.setObjectName(_fromUtf8("label_6"))
    self.label_7 = QtGui.QLabel(self.groupBox_2)
    self.label_7.setGeometry(QtCore.QRect(140, 80, 71, 16))
    self.label_7.setObjectName(_fromUtf8("label_7"))
    self.label_8 = QtGui.QLabel(self.groupBox_2)
    self.label_8.setGeometry(QtCore.QRect(140, 100, 71, 16))
    self.label_8.setObjectName(_fromUtf8("label_8"))
    self.label_11 = QtGui.QLabel(self.groupBox_2)
    self.label_11.setGeometry(QtCore.QRect(140, 120, 71, 16))
    self.label_11.setObjectName(_fromUtf8("label_11"))
    self.pushButton_5 = QtGui.QPushButton(self.groupBox_2)
    self.pushButton_5.setGeometry(QtCore.QRect(130, 140, 75, 23))
    self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
    self.label_19 = QtGui.QLabel(self.groupBox_2)
    self.label_19.setGeometry(QtCore.QRect(0, 80, 121, 16))
    self.label_19.setObjectName(_fromUtf8("label_19"))
    self.label_18 = QtGui.QLabel(self.groupBox_2)
    self.label_18.setGeometry(QtCore.QRect(0, 60, 131, 16))
    self.label_18.setObjectName(_fromUtf8("label_18"))
    self.label_17 = QtGui.QLabel(self.groupBox_2)
    self.label_17.setGeometry(QtCore.QRect(0, 100, 131, 16))
    self.label_17.setObjectName(_fromUtf8("label_17"))
    self.label_16 = QtGui.QLabel(self.groupBox_2)
    self.label_16.setGeometry(QtCore.QRect(0, 120, 131, 16))
    self.label_16.setObjectName(_fromUtf8("label_16"))

    self.retranslateUi(Dialog)
    QtCore.QMetaObject.connectSlotsByName(Dialog)

def retranslateUi(self, Dialog):
    Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
    self.pushButton.setText(_translate("Dialog", "Button1", None))
    self.pushButton_2.setText(_translate("Dialog", "Button2", None))
    self.pushButton_3.setText(_translate("Dialog", "Button3", None))
    self.label_20.setText(_translate("Dialog", "Konektuj se na bazu", None))
    self.label_21.setText(_translate("Dialog", "Ucitaj Detaljne Tacke", None))
    self.label_22.setText(_translate("Dialog", "Ucitaj Parcele", None))
    self.groupBox.setTitle(_translate("Dialog", "GroupBox1", None))
    self.label.setText(_translate("Dialog", "Oznaka Parcele:", None))
    self.pushButton_4.setText(_translate("Dialog", "Button4", None))
    self.label_4.setText(_translate("Dialog", "label4", None))
    self.label_9.setText(_translate("Dialog", "label9", None))
    self.label_3.setText(_translate("Dialog", "label3", None))
    self.label_5.setText(_translate("Dialog", "label5", None))
    self.label_2.setText(_translate("Dialog", "Povrsina parcele je:", None))
    self.label_12.setText(_translate("Dialog", "Broj Prelomnih Tacaka je:", None))
    self.label_13.setText(_translate("Dialog", "Nacin koriscenja je:", None))
    self.label_14.setText(_translate("Dialog", "WKT format geometrije je:", None))
    self.label_15.setText(_translate("Dialog", "Ucitaj podatke:", None))
    self.groupBox_2.setTitle(_translate("Dialog", "GroupBox2", None))
    self.label_10.setText(_translate("Dialog", "Broj Tacke", None))
    self.label_6.setText(_translate("Dialog", "label6", None))
    self.label_7.setText(_translate("Dialog", "label7", None))
    self.label_8.setText(_translate("Dialog", "label8", None))
    self.label_11.setText(_translate("Dialog", "label11", None))
    self.pushButton_5.setText(_translate("Dialog", "Button5", None))
    self.label_19.setText(_translate("Dialog", "Koordinata Y je:", None))
    self.label_18.setText(_translate("Dialog", "Koordinata X je:", None))
    self.label_17.setText(_translate("Dialog", "Da li ucestvuje u parceli:", None))
    self.label_16.setText(_translate("Dialog", "WKT oblik Geometrije", None))

比我的主python文件 - Vezba2.py我有这个:

import pypyodbc
import DetaljnaTacka
import Poligon
import Parcela
from GuiVezba2DialogQt4 import *
import sys

class MyForm(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
       QtCore.QObject.connect(self.ui.pushButton_4, QtCore.SIGNAL('clicked()'),self.
dispmessage)

    def dispmessage(self):
        self.ui.label_10.setText("Hello ")

if __name__ == "__main__":
    app = QtGui.QGuiApplication(sys.argv)
    myapp = MyForm()
    myapp.show()
    sys.exit(app.exec_())

当我运行程序时,使用debagger我将断点设为myapp=MyForm()。当该步骤尝试执行时,程序结束。我没有看到创建的GUI,我没有看到任何错误。

我该怎么办?

谢谢。

1 个答案:

答案 0 :(得分:0)

我弄错了。我键入:            #include "opencv2/opencv.hpp"代替app = QtGui.QGuiApplication

我有另一个问题。我做了一个app = QtGui.QApplication,我正在尝试用标题标签和数据创建他。

但是,当我尝试这个时:tableWidget

我有错误。我的列表myapp.ui.tableWidget.setHorizontalHeaderLabels(listaPolja)不是listaPolja

我在网上看到了一些文章,它说我必须先创建QStringList

QStringList位于QStringList。但是,当我尝试这个时,我发现错误:QtCore.QStringList

This is Where I saw, that QtCore has QStringList

我该怎么办?