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
Code:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QSqlRelationalTableModel>
#include <QSortFilterProxyModel>
#include <cn.h>
namespace Ui {
class Dialog;
}
{
Q_OBJECT
public:
explicit Dialog
(QWidget *parent
= 0);
~Dialog();
private slots:
void on_lineEdit_textChanged
(const QString &arg1
);
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
my cn.h (where i declare the database pointers)
Code:
#ifndef CN_H
#define CN_H
#include <QObject>
#include <QSqlDatabase>
{
Q_OBJECT
public:
static cn *_obj;
static cn *obj();
signals:
public slots:
};
#endif // CN_H
my cn.cpp(this create the database(next i edit this database with navicat))
Code:
#include "cn.h"
#include "QDir"
#include <QDebug>
cn *cn::_obj = new cn;
{
_db.
setDatabaseName(QDir::currentPath() + "/TutorilDb.sqlite");
if(_db.open()){
qDebug() << "Conexión a la base de datos exitosa =>" + _db.databaseName() + "<=";
}
else{
qDebug() << "Problemas para ejecutar la base de datos" + _db.databaseName();
}
}
cn *cn::obj()
{
if(!_obj){
_obj = new cn();
}
return _obj;
}
{
return _db;
}
my dialog.cpp
Code:
#include "dialog.h"
#include "ui_dialog.h"
ui(new Ui::Dialog)
{
ui->setupUi(this);
//traemos los datos a la tabla, estamos en el constructor
modPersonas->setTable("tbPersonas");
modPersonas
->setRelation
(modPersonas
->fieldIndex
("tipo"),
QSqlRelation("tbTipo",
"id",
"tipo"));
modPersonas->select();
//filtro de busquedas
proxyPersonas->setSourceModel(modPersonas);
proxyPersonas->setFilterCaseSensitivity(Qt::CaseInsensitive);
proxyPersonas->setFilterKeyColumn(-1);
ui
->cbCol
->addItems
(QStringList() <<
"Id" <<
"Nombre" <<
"Apellido");
ui->tableView->setModel(modPersonas);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog
::on_lineEdit_textChanged(const QString &arg1
) {
proxyPersonas->setFilterFixedString(arg1);
}
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
Code:
void Dialog
::on_lineEdit_textChanged(const QString &arg1
) {
proxyPersonas->setFilterFixedString(arg1);
}
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)
Re: setFilterFixedString doesn't work in my code
Do you see the table unfiltered?
Is the slot on_lineEdit_textChanged called?
Cheers,
_
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
Code:
proxyPersonas->setFilterFixedString("SomethingRandom");
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:
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,
_
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 :D
Re: setFilterFixedString doesn't work in my code
Quote:
Originally Posted by
Koch
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
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
I really happy for your help, this forum is amazing and you are awesome :D
Thanks :)
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
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.
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 :D
Re: setFilterFixedString doesn't work in my code
Quote:
Originally Posted by
Koch
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 :D
And how many views do you have in the code you posted? I can see one, called ui->tableView.
Re: setFilterFixedString doesn't work in my code
Sorry, idiom differences XDDD now i understand, thank for patience :D