Python Forum
What to do to avoid error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What to do to avoid error
#1
Hello, I am getting an error when calling function from apps_5 modul into main. I need those 3 modules, becouse a lot of code will be inside. Any help would be appreciatted.

An error:
Error:
Traceback (most recent call last):   File "/home/pi/Desktop/Qt4/Project/01/Test_Class/apps_5.py", line 8, in print_situation      self.checkBox = QtGui.QCheckBox(self) TypeError: arguments did not match any overloaded call:   QCheckBox(QWidget parent=None): argument 1 has unexpected type 'bool'   QCheckBox(QString, QWidget parent=None): argument 1 has unexpected type 'bool'
main:
# python 2.7.9

from PyQt4 import QtCore, QtGui
import gui_5
from apps_5 import print_situation
import sys


if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)

    gui_master = gui_5.QtGui.QWidget()
    master = gui_5.Ui_Form()
    master.setupUi(gui_master)

    master.checkBox.clicked.connect(print_situation)

    gui_master.show()
    sys.exit(app.exec_())
gui modul:
from PyQt4 import QtCore, QtGui
import apps_5
#from apps_2 import my_app


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_Form(object):

    def setupUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(400, 300)
        self.checkBox = QtGui.QCheckBox(Form)
        self.checkBox.setGeometry(QtCore.QRect(200, 150, 100, 26))
        self.checkBox.setObjectName(_fromUtf8("checkBox"))

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

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))
        self.checkBox.setText(_translate("Form", "CheckBox", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Form = QtGui.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
apps_5 modul:
# python 2.7.9
from PyQt4 import QtCore, QtGui
import gui_5


def print_situation(self):

    self.checkBox = QtGui.QCheckBox(self)
    if self.checkBox.checkState() == QtCore.Qt.Checked:
        print "Checked"
    else:
        print "Unchecked"
Reply
#2
(Jan-29-2017, 11:08 AM)California Wrote:
Error:
Traceback (most recent call last):   File "/home/pi/Desktop/Qt4/Project/01/Test_Class/apps_5.py", line 8, in print_situation      self.checkBox = QtGui.QCheckBox(self) TypeError: arguments did not match any overloaded call:   QCheckBox(QWidget parent=None): argument 1 has unexpected type 'bool'   QCheckBox(QString, QWidget parent=None): argument 1 has unexpected type 'bool'
# python 2.7.9
from PyQt4 import QtCore, QtGui
import gui_5


def print_situation(self):

    self.checkBox = QtGui.QCheckBox(self)
    if self.checkBox.checkState() == QtCore.Qt.Checked:
        print "Checked"
    else:
        print "Unchecked"

Sounds like print_situation() is being called with different parameters than you expect it is.  For example, what do you think "self" means here?  Because whatever you think it is, it's apparently a True/False.

My suggestion would be to either 1) change the function to have *args and then print them out so you see what it's actually getting called with, or 2) look up the docs for what button.click.connect does.
Reply
#3
Great improoving with your advice No.1. No error message this time with printed "Unchecked" when checkbox is checked and again "Unchecked" when checkbox is unchecked.
Button will be checke tomorrow, report is comming.

Thank you verry much for your help.

Regards, Vlado
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020