Results 1 to 11 of 11

Thread: Using QDataBrowser

  1. #1
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Using QDataBrowser

    I need some help with QDataBrowser object. I want to set it up manually (without designer's wizard).
    Qt Code:
    1. /* 'browser' is of type QDataBrowser,
    2.  'selected_tabel' is of type QString */
    3.  
    4. base = QSqlDatabase::database();
    5. filter = "SELECT * FROM " + selected_tabel;
    6. QSqlCursor curs = QSqlCursor (selected_tabel, TRUE, base);
    7.  
    8. browser->setSqlCursor (&curs, FALSE);
    9. browser->setFilter (filter);
    10. browser->refresh();
    To copy to clipboard, switch view to plain text mode 
    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.

  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: Using QDataBrowser

    You should assign a filled QSqlForm to it.

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

  3. #3
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using QDataBrowser

    Aye, I just found out I have to use QSqlForm Although it did seem too easy without that

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

  4. #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: Using QDataBrowser

    Quote Originally Posted by Lebowski
    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.

  5. #5
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using QDataBrowser

    Quote Originally Posted by jacek
    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.

  6. #6
    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: Using QDataBrowser

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

  7. #7
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using QDataBrowser

    Quote Originally Posted by jacek
    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?

  8. #8
    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: Using QDataBrowser

    Quote Originally Posted by Lebowski
    Ok, but do I need to create a widget (like QLineEdit) for each field?
    Yes, QSqlForm only passes data between widgets and QSqlRecord.

  9. #9
    Join Date
    Apr 2006
    Location
    Slovenia
    Posts
    33
    Thanks
    5
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using QDataBrowser

    Quote Originally Posted by jacek
    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?

  10. #10
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Using QDataBrowser

    QSqlrecord has method count() ...use it
    a life without programming is like an empty bottle

  11. #11
    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: Using QDataBrowser

    Quote Originally Posted by Lebowski
    And how do I postion them if I don't know the number of them?
    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.

Similar Threads

  1. QDataBrowser and QSqlCursor
    By ederbs in forum Qt Programming
    Replies: 8
    Last Post: 22nd October 2006, 18:25

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.