Results 1 to 5 of 5

Thread: displaying any table on a qdatatable

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

    Default displaying any table on a qdatatable

    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
    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: displaying any table on a qdatatable

    Quote Originally Posted by Philip_Anselmo
    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().

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

    Philip_Anselmo (9th May 2006)

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

    Default Re: displaying any table on a qdatatable

    Thanks for your answer, I know you're relly busy

    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:

    Qt Code:
    1. QSqlCursor cursor( DB_TABLA,TRUE );
    2. tabla = new QDataTable( &cursor );
    3. tabla->setSqlCursor ( &cursor, TRUE,FALSE);
    4. tabla->refresh();
    5. tabla->show();
    To copy to clipboard, switch view to plain text mode 

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

    [joke] I didn't violate anyone named segment [/joke]
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

  5. #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: displaying any table on a qdatatable

    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).

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

    Philip_Anselmo (9th May 2006)

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

    Thumbs up Re: displaying any table on a qdatatable

    IT'S ALIVE!!!!!!!
    finally
    it worked thanks JaCeK
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  2. Replies: 3
    Last Post: 5th October 2008, 23:41
  3. Displaying Image's Color Table
    By ramstormrage in forum Newbie
    Replies: 3
    Last Post: 13th May 2008, 17:07
  4. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  5. Displaying QAbstractItemModel in a Table
    By bmesing in forum Qt Programming
    Replies: 1
    Last Post: 28th March 2007, 11:11

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.