Results 1 to 6 of 6

Thread: Extract data from db then pass it to qtreeview

  1. #1
    Join Date
    Jul 2012
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Platforms
    Windows

    Question Extract data from db then pass it to qtreeview

    Hi,
    I'm totally a newbie. I have this project in mind. I want to search data from my database and if it finds it, it will display the selected data to my QTreeView. I have already a query that can connect to my Postgresql Database. Here is the code:

    import sys
    from PyQt4.QtSql import *

    def createConnection():
    db = QSqlDatabase.addDatabase("QPSQL");
    db.setHostName("localhost")
    db.setPort(5432)
    db.setDatabaseName("db")
    db.setUserName("username")
    db.setPassword("password")
    ok = db.open()

    query = QSqlQuery()
    query.exec_("select * from itemlist;")
    return True

    This is the code for connecting to my database. My table for example is composed of pkey,itemcode,description and Quantity. I have a QLineEdit in my Gui. In that QLineEdit,it will search the ItemCode from my table and when it finds an item, it will automatically send that item data to my QTreeView with its details. How can this be possible. I hope you could help me. Please.

    Best Regards,
    Nethan

  2. The following user says thank you to nethanjavier for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Extract data from db then pass it to qtreeview

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:


  5. #3
    Join Date
    Jul 2012
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Platforms
    Windows

    Question Re: Extract data from db then pass it to qtreeview

    Hi wysota,

    What do you mean by using private messages? I'm just explaining my part because I have no background in programming. Sorry if you felt like I'm just using it for my own good. Currently I'm using PyQt and it's hard to start. Hope you understand my situation. I also try my best to find solutions but when I don't have any of it, that's the time I go have to ask.
    For QSqlQuery, I already google anything that i find. Others said i should use bindvalues. But I don't see enough examples so that I could understand how to bind my QLineEdit to a column in my table db. Thank you so much wysota.

    Best Regards,
    Nethan

    Hi wysota,

    What do you mean by using private messages? I'm just explaining my part because I have no background in programming. Sorry if you felt like I'm just using it for my own good. Currently I'm using PyQt and it's hard to start. Hope you understand my situation. I also try my best to find solutions but when I don't have any of it, that's the time I go have to ask.
    For QSqlQuery, I already google anything that i find. Others said i should use bindvalues. But I don't see enough examples so that I could understand how to bind my QLineEdit to a column in my table db. Thank you so much wysota.

    Best Regards,
    Nethan

  6. The following user says thank you to nethanjavier for this useful post:


  7. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Extract data from db then pass it to qtreeview

    Quote Originally Posted by nethanjavier View Post
    What do you mean by using private messages? I'm just explaining my part because I have no background in programming. Sorry if you felt like I'm just using it for my own good. Currently I'm using PyQt and it's hard to start. Hope you understand my situation. I also try my best to find solutions but when I don't have any of it, that's the time I go have to ask.
    You are referring to my signature. It's not about you, some people tend to send private messages instead of asking here.

    Others said i should use bindvalues.
    I don't know who told you that but essentially bindValues() is used for something different.

    But I don't see enough examples so that I could understand how to bind my QLineEdit to a column in my table db. Thank you so much wysota.
    All you need is in the docs I linked to in my previous post.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:


  9. #5
    Join Date
    Jul 2012
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Platforms
    Windows

    Default Re: Extract data from db then pass it to qtreeview

    Hi,

    I've read so many documents but still can't figure out how to do it. Please help me wysota. I'm really a newbie in programming. What I have so far is a UI for it and convert it to python file. Then I have a connection python file. In my main.py file, this is the code:

    from UI import Ui_MainWindow
    from connection import createConnection

    class Form(QtGui.QWidget):
    def __init__(self,parent=None):
    super(Form,self).__init__(parent)
    self.ui = UI()
    self.ui.setupUi(self)

    def mymodel(self.model):
    self.proxyModel.setSourceModel(model)
    self.sourceView.setModel(model)


    after that...I don't know the code. I don't know how to query to a specific column in my table and if it finds the value,it passes it to the treeview. Please help me.


    Best Regards,
    Nethan

  10. The following user says thank you to nethanjavier for this useful post:


  11. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Extract data from db then pass it to qtreeview

    Honestly I have no idea what you are trying to do. I see no relation between what you posted earlier and what you posted now.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:


Similar Threads

  1. How to extract data from QFormLayout?
    By szisziszilvi in forum Qt Programming
    Replies: 5
    Last Post: 17th May 2011, 10:18
  2. Extract Item from the QTreeView
    By sajis997 in forum Qt Programming
    Replies: 2
    Last Post: 25th March 2011, 09:40
  3. extract data from photos
    By timmu in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2009, 10:38
  4. How can I extract raw data from a QPixmap?
    By ricardo in forum Qt Programming
    Replies: 3
    Last Post: 16th September 2009, 09:31
  5. extract data from sqlTablemodel
    By peace_comp in forum Qt Programming
    Replies: 1
    Last Post: 13th May 2008, 20:25

Tags for this Thread

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.