LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-14-2014, 05:14 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 562

Rep: Reputation: 84
python pyside & QInputDialog error


This is my testcase code;

Code:
from PySide import QtCore, QtGui

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(454, 358)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.radioButton = QtGui.QRadioButton(self.centralwidget)
        self.radioButton.setGeometry(QtCore.QRect(20, 50, 82, 17))
        self.radioButton.setObjectName("radioButton")
        self.textEdit = QtGui.QTextEdit(self.centralwidget)
        self.textEdit.setGeometry(QtCore.QRect(130, 50, 281, 231))
        self.textEdit.setObjectName("textEdit")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionNew_Window = QtGui.QAction(MainWindow)
        self.actionNew_Window.setObjectName("actionNew_Window")
        self.actionAbout = QtGui.QAction(MainWindow)
        self.actionAbout.setObjectName("actionAbout")
        self.actionQuit = QtGui.QAction(MainWindow)
        self.actionQuit.setObjectName("actionQuit")
        self.radioButton.clicked.connect(self.setText)
        

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.actionQuit, QtCore.SIGNAL("activated()"), MainWindow.close)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.radioButton.setText(QtGui.QApplication.translate("MainWindow", "RadioButton", None, QtGui.QApplication.UnicodeUTF8))
        self.actionNew_Window.setText(QtGui.QApplication.translate("MainWindow", "New Window", None, QtGui.QApplication.UnicodeUTF8))
        self.actionAbout.setText(QtGui.QApplication.translate("MainWindow", "About", None, QtGui.QApplication.UnicodeUTF8))
        self.actionQuit.setText(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8))

    def setText(self):
        text, ok = QtGui.QInputDialog.getText(self, "QInputDialog.getText()",
            "User name:", QtGui.QLineEdit.Normal,
            QtCore.QDir.home().dirName())
        if ok and text != '':
            self.textEdit.append(text)

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
This will start with no errors. However, when I select the radioButton I get the following returned;

Quote:
Traceback (most recent call last):
File "testcase.py", line 51, in setText
QtCore.QDir.home().dirName())
TypeError: 'PySide.QtGui.QInputDialog.getText' called with wrong argument types:
PySide.QtGui.QInputDialog.getText(Ui_MainWindow, str, str, PySide.QtGui.QLineEdit.EchoMode, unicode)
Supported signatures:
PySide.QtGui.QInputDialog.getText(PySide.QtGui.QWidget, unicode, unicode, PySide.QtGui.QLineEdit.EchoMode = QLineEdit.Normal, unicode = QString(), PySide.QtCore.bool, PySide.QtCore.Qt.WindowFlags = 0)
PySide.QtGui.QInputDialog.getText(PySide.QtGui.QWidget, unicode, unicode, PySide.QtGui.QLineEdit.EchoMode, unicode, PySide.QtCore.bool, PySide.QtCore.Qt.WindowFlags, PySide.QtCore.Qt.InputMethodHints)
Any idea how to pass the correct types to QInputDialog?

Many thanks in advance.

Last edited by sharky; 01-14-2014 at 05:15 PM.
 
Old 01-14-2014, 05:38 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,200

Rep: Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307
The first argument to getText() should the MainWindow instance that you passed to setupUI. It can't be self, in this case, because self is a direct subclass of object.
 
Old 01-15-2014, 06:59 AM   #3
sharky
Member
 
Registered: Oct 2002
Posts: 562

Original Poster
Rep: Reputation: 84
Quote:
Originally Posted by dugan View Post
The first argument to getText() should the MainWindow instance that you passed to setupUI. It can't be self, in this case, because self is a direct subclass of object.
Bam! "MainWindow" worked!

Thanks,

Last edited by sharky; 01-15-2014 at 07:03 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pyqt vs pyside Garda Programming 1 07-13-2012 05:46 PM
Python 2.6 dependencies error installing python-sqlite2-2.5.5-1.1.i586.rpm jmp007 Linux - Newbie 1 02-11-2011 11:05 AM
LXer: PySide - LGPL Python bindings for Qt LXer Syndicated Linux News 0 08-19-2009 04:01 PM
LXer: PySide Brings LGPL Qt to Python LXer Syndicated Linux News 0 08-19-2009 07:00 AM
Listen media player&python error on Debian Etch Xplosive Linux - Software 0 05-17-2006 05:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration