[PyQt] PyQt API 2: equivalent of Null QVariant?
Hello, I currently use the API 1, and use the isNull() method of QVariant to detect a Null QVariant. This is necessary to detect a NULL value in a database. It seems there is no equivalent in API2 of PyQt. None is used to model an invalid QVariant. But how to model a Null QVariant? http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#id13 Compare the output of the two following examples. Thanks Julien # Example 1: using API 1 for QVariant from PyQt4.QtSql import * import sys db = QSqlDatabase.addDatabase( QSQLITE ) db.setDatabaseName( :memory: ) if not db.open(): sys.exit(1) query = QSqlQuery() query.exec_( CREATE TABLE person ( firstname VARCHAR(20) , lastname VARCHAR(20) ); ) query.exec_( INSERT INTO person VALUES( 'Danny', 'Young'); ) query.exec_( INSERT INTO person ( firstname ) VALUES( 'Christine' ); ) query.exec_( INSERT INTO person VALUES( 'Lars', 'Gordon'); ) query.exec_( SELECT * FROM person; ) record = query.record() for i in range( record.count() ): print record.fieldName( i ), \t, print \n for i in range( record.count() ): while query.next(): for i in range( record.count() ): value = query.value(i) if value.isNull(): print NULL, \t, else: print value.toString(), \t, print # Example 2: using API 2 for QVariant import sys, sip sip.setapi('QVariant', 2) from PyQt4.QtSql import * db = QSqlDatabase.addDatabase( QSQLITE ) db.setDatabaseName( :memory: ) if not db.open(): sys.exit(1) query = QSqlQuery() query.exec_( CREATE TABLE person ( firstname VARCHAR(20) , lastname VARCHAR(20) ); ) query.exec_( INSERT INTO person VALUES( 'Danny', 'Young'); ) query.exec_( INSERT INTO person ( firstname ) VALUES( 'Christine' ); ) query.exec_( INSERT INTO person VALUES( 'Lars', 'Gordon'); ) query.exec_( SELECT * FROM person; ) record = query.record() for i in range( record.count() ): print record.fieldName( i ), \t, print \n for i in range( record.count() ): while query.next(): for i in range( record.count() ): value = query.value(i) if value == None: print NULL, \t, else: print value, \t, print ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Display of Japanese Characters on Mac
Hi, Ullrich Martini wrote: It should be u日本. you are right, with the 'u' I get not output at all instead of the garbled output. Hmm, unicode characters are somehow invisible? Regarding python: Could you please post whether you use 32 bit or 64 bit python? 64bit, preinstalled binary. Regarding the fonts: I have only original Apple Japanese fonts. Did you install some on your own? Except here I do not have any issue with displaying Japanese Text. Only Apple's. Maybe Hiragino Kaku Gothic is used. Yuya, ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt API 2: equivalent of Null QVariant?
Phil Thompson wrote: The short answer is that you can't. However... QVariant::isNull() typically delegates to the enclosed data's isNull() method (eg. QString::isNull()). So your example for API v1 will also work for API v2. It gets a bit more complicated if you are also using the QString v2 API because a null QString and an empty QString are both converted to an empty unicode object (although None is converted to a null QString when going in the other direction). I chose this asymmetric behaviour because QString() creates a null QString when often what is really meant is an empty QString. Thanks for your answer. I have checked that API2 for QVariant works by using isNull() as you said. But, I cannot use API2 for QString. This means that I must stick to API1 for QString, at least. Will API1 support be continued in the next versions of PyQt? Indeed, detecting NULL is for me very important. Thanks Julien ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] Number of rows after filter
Hi All I have a QtreeView with an QSortFilterProxyModel set as model When I fill the ProxyModel I can see all the data I supplied. So its working. Now I want to display somthing like 'x of y' after applying a filter. with x the number of remaining rows from the total y. So for short where can I find the number of rows theQSortFilterProxyModel is actuallly displaying? Thanks, Frans, ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt API 2: equivalent of Null QVariant?
On Tue, 21 Dec 2010 21:06:11 +0100, TP paratribulati...@free.fr wrote: Phil Thompson wrote: The short answer is that you can't. However... QVariant::isNull() typically delegates to the enclosed data's isNull() method (eg. QString::isNull()). So your example for API v1 will also work for API v2. It gets a bit more complicated if you are also using the QString v2 API because a null QString and an empty QString are both converted to an empty unicode object (although None is converted to a null QString when going in the other direction). I chose this asymmetric behaviour because QString() creates a null QString when often what is really meant is an empty QString. Thanks for your answer. I have checked that API2 for QVariant works by using isNull() as you said. But, I cannot use API2 for QString. This means that I must stick to API1 for QString, at least. Will API1 support be continued in the next versions of PyQt? Indeed, detecting NULL is for me very important. API v1 will be supported until PyQt5 or Python v4. Phil ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] Question about labels with status message
Hi, Abhishek, :) On Fri, 17 Dec 2010, Abhishek wrote: Hi all,I have a general coding question as opposed to specific to pyqt. In a gui, if I want to have a status message box (a QLabel) which should display messages from all components of the gui, what is the best way to go about it? Should all the components need to have a pointer to the QLabel? Or should I make a static class which any component can access and use this class to update the QLabel? Any other ideas? I would prefer having each component emit() a signal with the status text as the argument and then connect() those signals to the QLabel's setText() slot. ---Jason ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt API 2: equivalent of Null QVariant?
Phil Thompson wrote: API v1 will be supported until PyQt5 or Python v4. Is it contractual? Why Python v4? It seems to me that nobody knows when Python v4 will appear. Anyway, it seems to be a problem that API2 does not support NULL, even if it corresponds to side cases (as mine). Thanks, Julien ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt API 2: equivalent of Null QVariant?
you could just access sql through python instead of through qt, NULL would then correspond to None On Tue, 2010-12-21 at 23:52 +0100, TP wrote: Phil Thompson wrote: API v1 will be supported until PyQt5 or Python v4. Is it contractual? Why Python v4? It seems to me that nobody knows when Python v4 will appear. Anyway, it seems to be a problem that API2 does not support NULL, even if it corresponds to side cases (as mine). Thanks, Julien ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt API 2: equivalent of Null QVariant?
Erik Janssens wrote: you could just access sql through python instead of through qt, NULL would then correspond to None Thanks. Yes, it is possible to use for example the sqlite3 module, but there are facilities related to the GUI, available when using Qt: QSqlTableModel, QSqlRelationTableModel, etc. This is why I use Qt rather than sqlite3. Cheers, Julien ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] PyQt API 2: equivalent of Null QVariant?
On Tuesday 21 December 2010, 23:58:39 Erik Janssens wrote: you could just access sql through python instead of through qt, NULL would then correspond to None ...by the price of renouncing QtSql neck and crop. That's a high price to pay, isn't it? Sure, Camelot does this, but I really appreciate displaying tables with a million records with a few lines of code without any worry (thanks to Qt's decent fetch mechanics under the model/view covers). On Tue, 2010-12-21 at 23:52 +0100, TP wrote: Phil Thompson wrote: API v1 will be supported until PyQt5 or Python v4. Is it contractual? Why Python v4? It seems to me that nobody knows when Python v4 will appear. Anyway, it seems to be a problem that API2 does not support NULL, even if it corresponds to side cases (as mine). This is unfortunate, since sacrificing API 2 QVariants is a long ranging decision to better make _early_ on - changing it lately in a project will cause headaches, guaranteed (apart from the unpythonic annoyance, that let to inventing it in the first place). The question is, what would be the prize of getting away from that asymmetry? PyQt would always return None for QString::Null QVariants(), which cannot appended to, etc.. Anything else with significance? How about an QVariant API 3 with this behavior? Pete ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt