PDA

View Full Version : displaying any table on a qdatatable



Philip_Anselmo
9th May 2006, 18:05
I'm trying to make an app that displays a MySQL table on a QDataTable... I'm in trouble filling the table... and the main problem is that the user inputs the info of the table he wants to see, on the MainForm

The user inputs:
Host, DataBase, Username,Password and the table he wants to display....
as you may know the tables are diferent.. everyone has it's own columns and data..
so my problem is how to fill a QDataTable with any MySQL table that the user inputs.. as The user has no idea of the conformation and content of the table. And ofcourse he doesn't need to... the user only needs to know the host, database, his username, password, and the table he wants to see..

I can't get to see how to get it.. because I don't know how to get the numbre of columns so I can make a for maybe to be adding columns to de datatable as I need to.


Help PLZ :$

I can't find any info not even on the QT Books or MySQL books :(
if you need anymore info please ask :o

jacek
9th May 2006, 18:20
I don't know how to get the numbre of columns so I can make a for maybe to be adding columns to de datatable as I need to.
You don't have to know the number of columns. Just use QSqlCursor and QDataTable::setSqlCursor().

Philip_Anselmo
9th May 2006, 21:08
Thanks for your answer, I know you're relly busy :p

but it gives me a :

Violación de segmento
*** Segment Violation ***

I already had tryied that before but not with the setSqlCursor and on another cpp

I implemented it on the form.ui.h as this:



QSqlCursor cursor( DB_TABLA,TRUE );
tabla = new QDataTable( &cursor );
tabla->setSqlCursor ( &cursor, TRUE,FALSE);
tabla->refresh();
tabla->show();


where:
tabla is the QDataTable
DB_TABLA a public QString that captures the table name on the form inputed by the user

:crying: I didn't violate anyone named segment

jacek
9th May 2006, 21:34
You create that cursor on the stack and it will be destroyed as soon as it goes out of scope, leaving dangling pointers behind. Create that cursor on the heap (using the new operator).

Philip_Anselmo
9th May 2006, 22:12
IT'S ALIVE!!!!!!!
:D finally
it worked thanks JaCeK