Hi,

I've put together a simple test app that demonstrates the problem I'm having with QSettings.value() INT arguments on Windows.

An invalid argument type error causes the app to crash on startup. Line 37 of the attached file is the culprit. The line works without issue on OSX. Do I need to wrap the integer setting value in a string to work around the invalid type error? What's common practice for wrestling with integer Windows preference settings?

Thanks!
Scott


#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui


class MainWindow(QtGui.QMainWindow):
	def __init__(self, parent=None):
		QtGui.QMainWindow.__init__(self, parent)


		self.settings           = QtCore.QSettings()
		self.readSettings()
		
		
		w = QtGui.QWidget()
		self.setCentralWidget(w)
		
		vbox = QtGui.QVBoxLayout()
		w.setLayout(vbox)

		self.setWindowTitle(self.tr("Settings Test"))
		self.setMinimumSize(160,160)
		self.resize(480,320)



	def readSettings(self):

		# main window
		self.restoreState(self.settings.value("MainWindow/state").toByteArray())
		self.restoreGeometry(self.settings.value("MainWindow/geometry").toByteArray())

		# application
		self.dbHost             = self.settings.value("Application/dbHost",
													  QtCore.QVariant(QtCore.QString("localhost"))).toString()
		self.dbPort             = self.settings.value("Application/dbPort", 5432).toInt()[0]

		print "self.dbHost: ", self.dbHost
		print "self.dbPort: ", self.dbPort
		




if __name__ == "__main__":
	app = QtGui.QApplication(sys.argv)
	mainwindow = MainWindow()
	mainwindow.show()
	sys.exit(app.exec_())






On Nov 10, 2009, at 1:12 AM, Scott Frankel wrote:


Hi,

I'm getting a fatal error from the following QSettings line on Windows. But on Mac OSX, the same code runs without error. The exe log file says that argument 2 of settings.value() has an invalid type. That'd be my int.

The first line of the method reads a string value. That appears to function properly on both platforms.

Any suggestions?

Thanks!
Scott


def readSettings(self):

self.dbHost = self.settings.value("Application/dbHost", QtCore.QVariant(QtCore.QString("localhost"))).toString() # this works on both platforms

self.dbPort = self.settings.value("Application/dbPort", 5432).toInt()[0] # this fails on windows, but works on osx


_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt









_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to