Results 1 to 4 of 4

Thread: Filling combobox from database

  1. #1
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Filling combobox from database

    I'm trying to do an app that shows on a QDataTable any table chosen by the user on runtime
    the user inputs the host, database name, username and password.. to connect to any MySQL database

    actually it works fine it show etc. but the user must input the name of the table and the name of the database running on the MySQL server.. so he must know it..

    I'm thinking on modify it changing the LineEdits from DataBaseName and TableName to QComboBoxs... that get filled at the conection time through a query I guess or something, tha gets the databases and tables on each database... I'm guessing that that's too much asking

    So for now I'm trying to get the tables on a combobox from the inputed databases the combobox gets filled from the database to be like the "show tables" maybe.

    The idea is that the user at runtime inputs on the form only the hostname, databasename, username and password, clicks on connect and the combobox tables gets fille with the tables avaible on that database.. so the user only chooses from there the table he wants to see click populate and the qdatatable shows the table the user selected in the combobox...

    So the problem is to fill the combobox with the tables from the database inputed from user....

    Any ideas? help plz I just can't find any info anywhere and the Qt books doesn't helpme on that...

    I'm still a n00b
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filling combobox from database

    Quote Originally Posted by Philip_Anselmo
    So for now I'm trying to get the tables on a combobox from the inputed databases the combobox gets filled from the database to be like the "show tables" maybe.
    What did you try so far? Do you know how to add a string to the combo box?

  3. #3
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filling combobox from database

    by now I haven't thinked on how to fill it because I need first how to get the data because the actual way to fill the combobox should be asigning the values capured through a QSqlCursor, but if I can't get the tables from the database with the cursor... I need to find other way

    The cursor gets filled with the table when created.. so I'm guessing it won't helpme so there must be another way to get the tables from the database.... so once I know the tables I can asign them to the qcombobox.

    I'm just guessing here as I have no idea eraly so if somenoe has done this before an have knoledge of this please help or with some code I could see to get an idea.
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filling combobox from database

    Quote Originally Posted by Philip_Anselmo
    but if I can't get the tables from the database with the cursor... I need to find other way
    There are two ways: either use QSqlQuery or QSqlDatabase::tables(). The latter will work with any database.

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

    Philip_Anselmo (11th May 2006)

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. cannot share the database connection!!!!
    By cbarmpar in forum Qt Programming
    Replies: 13
    Last Post: 23rd September 2008, 14:42
  3. Multiple database connections
    By cyberboy in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2008, 16:56
  4. Database Master-Detail Entry Form
    By Phan Sin Tian in forum Newbie
    Replies: 4
    Last Post: 3rd February 2008, 14:31

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.