Results 1 to 10 of 10

Thread: QTable - Data Base Problem

  1. #1
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default QTable - Data Base Problem

    Hello,
    I need little help. I am writeing a small library data base using QT Designer. And I got a problem. I don't know how to load data from file to QTable object that I've got on my form. Example file:
    cell_01;cell_02;cell_03;cell_04
    cell_05;cell_06;cell_07;cell_08
    cel1_09;cell_l0;cell_11;cell_12
    cell_13;cell_14;cell_l5;cell_l6
    etc...
    And I want to load this into my QTable object so that will look like that:
    http://img255.imageshack.us/img255/2291/qtra9.jpg

    Please, help me.
    esq

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTable - Data Base Problem

    I don't know how to load data from file to QTable
    Is this a data base file or just a "normal" text/binary file?
    If its a database, which one is it?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - Data Base Problem

    this is normal text file

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTable - Data Base Problem

    Look up QFile and QTextStream in the docs to see how you can read the file.
    If you still have specific questions, post them here.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - Data Base Problem

    Ok, thanks for that.
    I'm new at QT and kind lost in this at the time.
    I wrote a function and it is inserting values into specific cells using lineEdit fields. It looks like this:
    void Form1::wpiszWart()
    {
    int row = table4->numRows();
    table4->insertRows(row);
    table4->setText(row, 0, lineEdit1->text());
    table4->setText(row, 1, lineEdit2->text());
    table4->setText(row, 2, lineEdit3->text());
    table4->setText(row, 3, lineEdit4->text());
    }
    Could You help me write some little code example how to save cell vaule into file and then how to open the file and insert that value into specific cell?
    Thanks in advance!
    Last edited by esq; 23rd May 2007 at 21:45.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTable - Data Base Problem

    Could You help me write some little code example how to save cell vaule into file and then how to open the file and insert that value into specific cell?
    Well, I could.
    But at the same tocken you could just read the docs, which already supply all the examples you need!
    From the docs:
    Qt Code:
    1. QFile file( "file.txt" );
    2. if ( file.open( IO_ReadOnly ) ) {
    3. QTextStream stream( &file );
    4. QString line;
    5. int i = 1;
    6. while ( !stream.atEnd() ) {
    7. line = stream.readLine(); // line of text excluding '\n'
    8. printf( "%3d: %s\n", i++, line.latin1() );
    9. lines += line;
    10. }
    11. file.close();
    12. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - Data Base Problem

    thanks for that!

    I've got another question. How to get value from specific cell from QTable and insert it into lineEdit field? I know how to get value from lineEdit and insert it into specific cell, but i've got problems with the opposite situation.

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTable - Data Base Problem

    Why don't you ask the model, using itemData?

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTable - Data Base Problem

    Oh, are you using Qt3?
    Then use QTable::text(int row, int col ).
    Should work fine.

    Regards

  10. The following user says thank you to marcel for this useful post:

    esq (27th May 2007)

  11. #10
    Join Date
    May 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QTable - Data Base Problem

    thanks! it works fine

Similar Threads

  1. QTable - Date Base Problem
    By esq in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2007, 02:32
  2. problem with reading input data in qt
    By Ahmad in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2007, 10:58
  3. QTable resize problem with large tables
    By Robzzz in forum Newbie
    Replies: 3
    Last Post: 22nd May 2006, 14:13
  4. Replies: 16
    Last Post: 7th March 2006, 15:57
  5. Problem with QTable
    By zlatko in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2006, 10:00

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.