Results 1 to 3 of 3

Thread: Printing non-ascii characters.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Printing non-ascii characters.

    Hi,

    after a quest for connecting to an odbc data source and after much documentation reading, i finally have a snippet that i can connect and execute a parameterized stored procedure!

    The sp is a simple one, getting an integer and returning one colymn of string data

    The only 2 questions i have is that if i HAVE to declare the stored procedure parameter type as QVariant(4) or is another way to do this,
    and (more important) how i can print non-ascii data that exists in the result set...

    I am using Eclipse/PyDev (if that matters) but i print garbage from the snipet below,
    and am not sure if the i correctly coded the part about QVariant.toString and QtCore.QString.toUtf8(candidate). (i am propably not...)

    In a real app would put the data in a grid but what about now ?? I check the variable"candidate" in the debugger and it correctly contains the Greek characters that came from the database, but how i can...print them ??
    Is there something in Qt that i am not doing (or at all...) correcltly ?


    Code is below:

    Qt Code:
    1. # -*- coding: utf-8 -*-
    2.  
    3. import sys
    4. from PyQt4 import QtCore, QtSql, QtGui
    5.  
    6. app = QtGui.QApplication(sys.argv)
    7. db = QtSql.QSqlDatabase.addDatabase("QODBC");
    8. db.setDatabaseName("pm");
    9. f = db.open()
    10.  
    11. if f:
    12. print "Connected"
    13. query = QtSql.QSqlQuery(db)
    14. query.prepare("{call graduation_fetch(?)}")
    15. query.setForwardOnly(True)
    16. query.bindValue(0, QtCore.QVariant(4), QtSql.QSql.In)
    17. query.exec_()
    18.  
    19. while query.next():
    20. candidate = QtCore.QVariant.toString(query.value(0))
    21. print QtCore.QString.toUtf8(candidate)
    22.  
    23. db.close()
    To copy to clipboard, switch view to plain text mode 

    and of course, thanks for any help!
    Last edited by kikapu; 24th June 2007 at 18:19.
    Software Engineer, riding a Kona King Kikapu 2007

Similar Threads

  1. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 14:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.