Results 1 to 12 of 12

Thread: QSqlTableModel/QSqlQueryModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QSqlTableModel/QSqlQueryModel

    I have one thing about setFilter.
    Normally the use of setFilter is this: model.setFilter("Materiaal = 'Koolstofstaal'"); and this works fine.
    Have anybody try this with a bigger string:
    model.setFilter("Materiaal = 'Koolstofstaal' and Materiaal = 'Gelegeerdstaal' and Materiaal = 'Gereeedshapstaal'");
    If i try this there nothing showing up in my lineEdits.
    I want put this strings together to make a choice of a item in my combobox.
    thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QSqlTableModel/QSqlQueryModel

    Try "or" instead of "and"...
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QSqlTableModel/QSqlQueryModel

    I have tried model.setFilter("Materiaal = 'Koolstofstaal' or Materiaal = 'Gelegeerdstaal'or Materiaal = 'Gereedschapstaal'");
    With no succes it shows only the first string Materiaal = 'Koolstofstaal'

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QSqlTableModel/QSqlQueryModel

    What value does model.rowCount() return after setFilter() and select()?

  5. #5
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QSqlTableModel/QSqlQueryModel

    This a part of the code.
    void MainWindow::search()
    {
    searchDialog dlg(this)
    QString mat = dlg.leMateriaalComboBox->currentText()
    if(dlg.exec() == QDialog::Accepted) {

    QSqltableModel model;
    model.setTable("frezen");
    model.setFilter("Materiaal ='Koolstofstaal' or Materiaal = 'Gelegeerdstaal' or Materiaal = 'Gereedschapstaal'");
    model.select();

    for (int i = 0; i < model.rowCount(); ++i) {
    mat = model.record(i).value("Materiaal").toString();
    leMateriaal->setText(mat);
    }
    }
    The value from model.rowCount() is only the first part of the setFilter string ( Koolstofstaal ) the orther value's doesn't show up in the lineEdit in Mainwindow.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: QSqlTableModel/QSqlQueryModel

    Quote Originally Posted by dragon View Post
    model.setFilter("Materiaal ='Koolstofstaal' or Materiaal = 'Gelegeerdstaal' or Materiaal = 'Gereedschapstaal'");
    ...
    mat = model.record(i).value("Materiaal").toString();
    Do you really need a model for this? It seems you know a priori what values you want to display (i.e. "Koolstofstaal", "Gelegeerdstaal" and "Gereedschapstaal").

    Quote Originally Posted by dragon View Post
    the orther value's doesn't show up in the lineEdit in Mainwindow.
    QLineEdit::setText() sets the text --- it doesn't append it.
    Qt Code:
    1. lineEdit->setText( "aaa" ); // after this line lineEdit will contain "aaa"
    2. lineEdit->setText( "bbb" ); // now "aaa" is replaced by "bbb"
    To copy to clipboard, switch view to plain text mode 
    If you want to display several values, concatenate them.

    But I think that you would rather want to use a QComboBox instead of QLineEdit.

  7. #7
    Join Date
    Jan 2006
    Posts
    115
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 1 Time in 1 Post

    Default Re: QSqlTableModel/QSqlQueryModel

    Yes i want to use in searchDialog the combobox.
    Maby i chance the code for this program.
    Thanks jacek voor your time and answers.

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
  •  
Qt is a trademark of The Qt Company.