Results 1 to 11 of 11

Thread: setFilterFixedString doesn't work in my code

  1. #1
    Join Date
    Dec 2014
    Posts
    11
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default setFilterFixedString doesn't work in my code

    Hello!
    First at all, my english is really really bad, sorry for this :c

    Well, I maked a program, with a lineedit, this lineedit is for filtering the database

    the database is a .sqlite file

    The database was edited in navicat for sqlite

    My SO is Windows XP SP 3 and my qt version is QT 5.0.2, but i tried this code in 5.2.1 and 5.3.2 and doesn't work ...
    and the compiler is Minwg 4.7 , but i tried with 4.8 and 4.8.2

    this is my dialog.h
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QDialog>
    5. #include <QSqlRelationalTableModel>
    6. #include <QSortFilterProxyModel>
    7. #include <cn.h>
    8.  
    9. namespace Ui {
    10. class Dialog;
    11. }
    12.  
    13. class Dialog : public QDialog
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. explicit Dialog(QWidget *parent = 0);
    19. ~Dialog();
    20. QSqlRelationalTableModel * modPersonas;
    21. QSortFilterProxyModel * proxyPersonas;
    22.  
    23.  
    24. private slots:
    25. void on_lineEdit_textChanged(const QString &arg1);
    26.  
    27. private:
    28. Ui::Dialog *ui;
    29. };
    30.  
    31. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    my cn.h (where i declare the database pointers)
    Qt Code:
    1. #ifndef CN_H
    2. #define CN_H
    3.  
    4. #include <QObject>
    5. #include <QSqlDatabase>
    6.  
    7. class cn : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit cn(QObject *parent = 0);
    12.  
    13. static cn *_obj;
    14. static cn *obj();
    15.  
    16. static QSqlDatabase _db;
    17. static QSqlDatabase db();
    18.  
    19. signals:
    20.  
    21. public slots:
    22.  
    23. };
    24.  
    25. #endif // CN_H
    To copy to clipboard, switch view to plain text mode 

    my cn.cpp(this create the database(next i edit this database with navicat))
    Qt Code:
    1. #include "cn.h"
    2. #include "QDir"
    3. #include <QDebug>
    4.  
    5.  
    6. QSqlDatabase cn::_db = QSqlDatabase::addDatabase("QSQLITE");
    7. cn *cn::_obj = new cn;
    8.  
    9. cn::cn(QObject *parent) :
    10. QObject(parent)
    11. {
    12. _db.setDatabaseName(QDir::currentPath() + "/TutorilDb.sqlite");
    13. if(_db.open()){
    14. qDebug() << "Conexión a la base de datos exitosa =>" + _db.databaseName() + "<=";
    15. }
    16. else{
    17. qDebug() << "Problemas para ejecutar la base de datos" + _db.databaseName();
    18. }
    19. }
    20.  
    21. cn *cn::obj()
    22. {
    23. if(!_obj){
    24. _obj = new cn();
    25. }
    26. return _obj;
    27. }
    28.  
    29. QSqlDatabase cn::db()
    30. {
    31. return _db;
    32. }
    To copy to clipboard, switch view to plain text mode 

    my dialog.cpp
    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3.  
    4. Dialog::Dialog(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::Dialog)
    7. {
    8. ui->setupUi(this);
    9. //traemos los datos a la tabla, estamos en el constructor
    10. modPersonas = new QSqlRelationalTableModel(this, cn::db());
    11. modPersonas->setTable("tbPersonas");
    12. modPersonas->setRelation(modPersonas->fieldIndex("tipo"), QSqlRelation("tbTipo", "id", "tipo"));
    13. modPersonas->select();
    14.  
    15. //filtro de busquedas
    16. proxyPersonas = new QSortFilterProxyModel(this);
    17. proxyPersonas->setSourceModel(modPersonas);
    18. proxyPersonas->setFilterCaseSensitivity(Qt::CaseInsensitive);
    19. proxyPersonas->setFilterKeyColumn(-1);
    20.  
    21. ui->cbCol->addItems(QStringList() << "Id" << "Nombre" << "Apellido");
    22.  
    23. ui->tableView->setModel(modPersonas);
    24. }
    25.  
    26. Dialog::~Dialog()
    27. {
    28. delete ui;
    29. }
    30.  
    31. void Dialog::on_lineEdit_textChanged(const QString &arg1)
    32. {
    33. proxyPersonas->setFilterFixedString(arg1);
    34. }
    To copy to clipboard, switch view to plain text mode 

    well, here is my problem, this compile good, but, when i write in the line edit, this doesnt filter, and i don't know why
    Qt Code:
    1. void Dialog::on_lineEdit_textChanged(const QString &arg1)
    2. {
    3. proxyPersonas->setFilterFixedString(arg1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    If you know what im doing bad, i'll be very grateful

    Thanks c:

    ps: sorry for spanish text in the code, i use this for know what does each part (que hace cada parte, i dont know if a translate correctly this XD)

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setFilterFixedString doesn't work in my code

    Do you see the table unfiltered?
    Is the slot on_lineEdit_textChanged called?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2014
    Posts
    11
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setFilterFixedString doesn't work in my code

    Yes, the table doesn't filtered. This is the problem.

    And, i almost sure that the function work, but, i tried put this in the constructor
    Qt Code:
    1. proxyPersonas->setFilterFixedString("SomethingRandom");
    To copy to clipboard, switch view to plain text mode 
    And doesn't work.
    (In this place i put strings like 1, 2, 3, 4, Joseth, and other things that are on the list and doesn't work too.)

    Thx 4 answer c:

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setFilterFixedString doesn't work in my code

    Line 23 in your code snippet.
    You are using the original model on the view, not the filtered one.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    Koch (23rd December 2014)

  6. #5
    Join Date
    Dec 2014
    Posts
    11
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setFilterFixedString doesn't work in my code

    I should put the line 23 in the function? or i should put another thing?

    sorry for my delay in my answer

    Thx again for help

    Edit: Goddam I am a complete idiot, god, ***** **** **** i have an extra cromoson or something like that, god, I Really thank you.
    proxyPersonas, damn.

    I really happy for your help, this forum is amazing and you are awesome
    Last edited by Koch; 23rd December 2014 at 00:07.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setFilterFixedString doesn't work in my code

    Quote Originally Posted by Koch View Post
    I should put the line 23 in the function? or i should put another thing?
    I know you've got it already but I should have phrased my answer better


    Quote Originally Posted by Koch View Post
    Edit: Goddam I am a complete idiot, god, ***** **** **** i have an extra cromoson or something like that, god, I Really thank you.
    proxyPersonas, damn.
    Hehe. Happens to all of us at times, the reason code review systems are so valuable.
    Sometime one just doesn't see the code one has written but what one assumes should be there.

    And as we can see from my initial response I didn't see it at first either, but instead had some ideas what the problem could be.

    Quote Originally Posted by Koch View Post
    I really happy for your help, this forum is amazing and you are awesome
    Thanks

  8. #7
    Join Date
    Dec 2014
    Posts
    11
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setFilterFixedString doesn't work in my code

    I have a question:
    Are there a function that return the row that is selected?

    For example, I click in the row 3 and this function return 3.

    Thx

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setFilterFixedString doesn't work in my code

    The view has a selection model available. In addition, the view has a clicked signal to report clicks on items.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Koch (24th December 2014)

  11. #9
    Join Date
    Dec 2014
    Posts
    11
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setFilterFixedString doesn't work in my code

    I can't understand
    At what library you mean?
    Because view is very broad to search XD

    If you can be more specific i'll be very grateful

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setFilterFixedString doesn't work in my code

    Quote Originally Posted by Koch View Post
    I can't understand
    At what library you mean?
    Because view is very broad to search XD

    If you can be more specific i'll be very grateful
    And how many views do you have in the code you posted? I can see one, called ui->tableView.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. The following user says thank you to wysota for this useful post:

    Koch (25th December 2014)

  14. #11
    Join Date
    Dec 2014
    Posts
    11
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: setFilterFixedString doesn't work in my code

    Sorry, idiom differences XDDD now i understand, thank for patience

Similar Threads

  1. Replies: 3
    Last Post: 12th June 2012, 08:57
  2. Why this code doesn't work?
    By prykHetQuo in forum Qt Programming
    Replies: 2
    Last Post: 11th February 2009, 19:08
  3. why doesn't the button work?
    By mattia in forum Newbie
    Replies: 18
    Last Post: 5th November 2007, 12:14
  4. setMouseTracking() doesn't work.
    By luffy27 in forum Qt Programming
    Replies: 13
    Last Post: 27th April 2007, 18:16
  5. setWindowOpacity doesn't work!
    By nupul in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2006, 18:28

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.