PDA

View Full Version : Using QDataBrowser



Lebowski
24th April 2006, 13:18
I need some help with QDataBrowser object. I want to set it up manually (without designer's wizard).


/* 'browser' is of type QDataBrowser,
'selected_tabel' is of type QString */

base = QSqlDatabase::database();
filter = "SELECT * FROM " + selected_tabel;
QSqlCursor curs = QSqlCursor (selected_tabel, TRUE, base);

browser->setSqlCursor (&curs, FALSE);
browser->setFilter (filter);
browser->refresh();

What am I missing? It compiles normally but I get blank data browser. How do I get fields and data from database? Connection is definitelly working as I have no problems showing same data in a table.

jacek
24th April 2006, 13:53
You should assign a filled QSqlForm to it.

PS. filter should contain only the condition from the WHERE clause.

Lebowski
24th April 2006, 14:02
Aye, I just found out I have to use QSqlForm :crying: Although it did seem too easy without that :D

p.s.
Only condition from 'WHERE'? So if I want to print out everything I just pass "1" to setFilter()?

jacek
24th April 2006, 14:09
Only condition from 'WHERE'? So if I want to print out everything I just pass "1" to setFilter()?
Yes, but AFAIR you can pass an empty string too.

Lebowski
3rd May 2006, 14:56
You should assign a filled QSqlForm to it.

Is it possible to make a QSqlForm with variable number of fields / widgets?

For example: some table will have 3 fields yet a different one might have 5 fields.

jacek
3rd May 2006, 15:25
Is it possible to make a QSqlForm with variable number of fields / widgets?
When you create the QSqlForm, it's empty. Then you can populate it with any number of fields using QSqlForm::insertField().

Lebowski
4th May 2006, 06:16
When you create the QSqlForm, it's empty. Then you can populate it with any number of fields using QSqlForm::insertField().
Ok, but do I need to create a widget (like QLineEdit) for each field?

jacek
4th May 2006, 13:17
Ok, but do I need to create a widget (like QLineEdit) for each field?
Yes, QSqlForm only passes data between widgets and QSqlRecord.

Lebowski
4th May 2006, 13:59
Yes, QSqlForm only passes data between widgets and QSqlRecord.
But how do I create widgets if I don't know exact number of them?
Is it even possible to create them in FOR loop that will run from 1 to 'number of fields'? And how do I postion them if I don't know the number of them? :confused:

zlatko
4th May 2006, 14:43
QSqlrecord has method count() ...use it :rolleyes:

jacek
4th May 2006, 14:56
And how do I postion them if I don't know the number of them? :confused:
You can use layouts for this. For example a grid layout with two columns --- one for a label and one for a widget.

Another solution is to use a QTable or QListView, but you won't be able to use the QSqlForm with it.