Results 1 to 8 of 8

Thread: QSqlTableModel

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default QSqlTableModel

    Hello there,

    I have one problem in setting the filter from the above metioned object. So I have an QSqlTableModel and when I set my filter like this (line 7)
    Qt Code:
    1. ValidToFilter->addItem("9999-12-31 23:59:59");
    2. QString product = ProductFilter->currentText();
    3. QString date = ValidToFilter->currentText();
    4. QString eingabeFilter = "vcProductID='"+product+"'";
    5. QString validationFilter = "dtValidTo='"+date+"'";
    6. QString price = "dcPrice='0.200'";
    7. model->setFilter( eingabeFilter +" and "+dcPrice);
    To copy to clipboard, switch view to plain text mode 
    everything is ok with multiple filter argument but when I change the second filter argument to this
    Qt Code:
    1. model->setFilter( eingabeFilter +" and "+validationFilter );
    2. view->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    my view is empty. The second filterargument is an Datetime type on the mssql server table
    So what do I wrong I have to filter the column on the sql server. For example this is one representativ entry in the column with datetime type : 9999-12-31 23:59:59.000

    anybody some idea???
    Last edited by codeman; 24th April 2009 at 12:55.

  2. #2
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlTableModel

    maybe here
    Qt Code:
    1. QString date = ValidToFilter->currentText();
    To copy to clipboard, switch view to plain text mode 
    you get 9999-12-31 23:59:59 not 9999-12-31 23:59:59.000
    so change
    Qt Code:
    1. QString validationFilter = "dtValidTo='"+date+"'";
    To copy to clipboard, switch view to plain text mode 
    to
    Qt Code:
    1. QString validationFilter = "dtValidTo like '"+date+"%'";
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: QSqlTableModel

    thank you.

    So I change it in your way. now my view is not empty but in my datetime column there are some wrong filter elements. I choose 9999-12-31 23:59:59.000 as filter but there are also elements like this 30.06.2008 23:59:59 or see attachment for more detail ....
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlTableModel

    do you use
    Qt Code:
    1. model->select();
    To copy to clipboard, switch view to plain text mode 
    after setFilter ?

  5. #5
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: QSqlTableModel

    Yes I do. This is the actual code

    Qt Code:
    1. void TableEditor::refresh()
    2. {
    3. QString product = ProductFilter->currentText();
    4. QString date = ValidToFilter->currentText();
    5. QString eingabeFilter = "vcProductID='"+product+"'";
    6. QString validationFilter = "dtValidTo like '"+date+"%'";
    7. model->setFilter( eingabeFilter +" and "+validationFilter );
    8. model->select();
    9. view->setModel(model);
    10. }
    To copy to clipboard, switch view to plain text mode 

    It seems that the second filter argument don´t grab correctly ?????

  6. #6
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: QSqlTableModel

    So I solve the problem: It must be

    Qt Code:
    1. QString validationFilter = "dtValidTo= convert (datetime,'"+date+"',120)";
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: QSqlTableModel

    But I have one question.

    When I set the strategy from my SqlTableModel on manual, I have problems when I change a column with the mssql datatype Datetime on the server on submitting the datas.

    For example in my model one entry in the column is 31.12.2008 23:50:59 and when I change something and try to submit it occurs an error.

    What kind of problem I have to solve here???

  8. #8
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: QSqlTableModel

    Hello friends I locate the problem exactly now. It ist a Datetime field overflow.

    The entry in the column is 9999-12-31 23:59:59 and whne I try to change it and submit it occurs the field overflow error.

    The MsSql server holds this value in the database but why it occurs the mentioned error.??

Similar Threads

  1. QSqlTableModel & treeview
    By janEUcitzen in forum Qt Programming
    Replies: 6
    Last Post: 14th November 2008, 21:00
  2. QSqlTableModel inserts empty rows
    By Nesbitt in forum Qt Programming
    Replies: 2
    Last Post: 6th August 2008, 13:47
  3. Replies: 4
    Last Post: 9th May 2008, 18:02
  4. Subclassing QSqlTableModel to overwrite setQuery
    By montuno in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2007, 11:32
  5. QSqlTableModel verticak header connect
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 1st July 2007, 14:07

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.