Results 1 to 7 of 7

Thread: PyQT Database etc

  1. #1
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default PyQT Database etc

    Hi. I am using PyQT to create a database system as a part of a uni project based around a bakery. I am using the QT database access libraries as opposed to the built in python ones.

    What I want to do is load values from one of the fields in the database as a list in a QListWidget so then when each value is click appropriate data can be placed into fields to the right of it.

    Any help would be hugely appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQT Database etc

    Sorry, but what do you expect from us? What did YOU try so far? Have you seen the examples shipped with Qt/PyQt?
    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQT Database etc

    I haven't tried much to be honest. I was after ideas more than an implementation. From what I understand of QListWidget it works like an array, in which case the best idea i have so far is listing all values within the field and then adding them to the QListWidget. Then to find details on a specific bit doing a search through the database for that name, however this seems rather wasteful I was really after better understanding as to how QLIstWidget works.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQT Database etc

    Well, an SQL model + view is much better choice for showing data from database...
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    peterjb31 (27th March 2008)

  6. #5
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQT Database etc

    Thanks, that makes a lot more sense that what I was trying to do. I am however still struggling to work out how to implement this. I read some documentation on QListView and the QSqlQueryModel here.

    I don't understand how I create the model and then reference it. If anyone could either point me to an example of the code used (can't seem to find any for pyqt when I google) or alternatively post an example I would be extremely greatful.

  7. #6
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQT Database etc

    I have created a QSqlModel using the following code in Python:

    Qt Code:
    1. self.model = QSqlQueryModel
    2. self.model.setQuery("SELECT companyName FROM suppliers");
    To copy to clipboard, switch view to plain text mode 

    However when I try to run the code I get the following error:

    TypeError: first argument of unbound method QSqlQueryModel.setQuery() must be a QSqlQueryModel instance
    Would anyone be able to advise as to what the error is. Have I declared the QueryModel properly, if not how do I?

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: PyQT Database etc

    Excuse me, I'm not a Python expert but shouldn't it be:
    Qt Code:
    1. self.model = QSqlQueryModel()
    To copy to clipboard, switch view to plain text mode 
    ?
    J-P Nurmi

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 09:30
  2. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 17:50
  3. Database Master-Detail Entry Form
    By Phan Sin Tian in forum Newbie
    Replies: 4
    Last Post: 3rd February 2008, 15:31
  4. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 18:50
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 18:53

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.