PDA

View Full Version : Filling combobox from database



Philip_Anselmo
11th May 2006, 16:56
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 :(

jacek
11th May 2006, 17:03
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?

Philip_Anselmo
11th May 2006, 17:48
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 :o or with some code I could see to get an idea.

jacek
11th May 2006, 17:53
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.