Koch
20th December 2014, 22:13
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
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QSqlRelationalTableModel>
#include <QSortFilterProxyModel>
#include <cn.h>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
QSqlRelationalTableModel * modPersonas;
QSortFilterProxyModel * proxyPersonas;
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)
#ifndef CN_H
#define CN_H
#include <QObject>
#include <QSqlDatabase>
class cn : public QObject
{
Q_OBJECT
public:
explicit cn(QObject *parent = 0);
static cn *_obj;
static cn *obj();
static QSqlDatabase _db;
static QSqlDatabase db();
signals:
public slots:
};
#endif // CN_H
my cn.cpp(this create the database(next i edit this database with navicat))
#include "cn.h"
#include "QDir"
#include <QDebug>
QSqlDatabase cn::_db = QSqlDatabase::addDatabase("QSQLITE");
cn *cn::_obj = new cn;
cn::cn(QObject *parent) :
QObject(parent)
{
_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;
}
QSqlDatabase cn::db()
{
return _db;
}
my dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
//traemos los datos a la tabla, estamos en el constructor
modPersonas = new QSqlRelationalTableModel(this, cn::db());
modPersonas->setTable("tbPersonas");
modPersonas->setRelation(modPersonas->fieldIndex("tipo"), QSqlRelation("tbTipo", "id", "tipo"));
modPersonas->select();
//filtro de busquedas
proxyPersonas = new QSortFilterProxyModel(this);
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
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)
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
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QSqlRelationalTableModel>
#include <QSortFilterProxyModel>
#include <cn.h>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
QSqlRelationalTableModel * modPersonas;
QSortFilterProxyModel * proxyPersonas;
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)
#ifndef CN_H
#define CN_H
#include <QObject>
#include <QSqlDatabase>
class cn : public QObject
{
Q_OBJECT
public:
explicit cn(QObject *parent = 0);
static cn *_obj;
static cn *obj();
static QSqlDatabase _db;
static QSqlDatabase db();
signals:
public slots:
};
#endif // CN_H
my cn.cpp(this create the database(next i edit this database with navicat))
#include "cn.h"
#include "QDir"
#include <QDebug>
QSqlDatabase cn::_db = QSqlDatabase::addDatabase("QSQLITE");
cn *cn::_obj = new cn;
cn::cn(QObject *parent) :
QObject(parent)
{
_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;
}
QSqlDatabase cn::db()
{
return _db;
}
my dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
//traemos los datos a la tabla, estamos en el constructor
modPersonas = new QSqlRelationalTableModel(this, cn::db());
modPersonas->setTable("tbPersonas");
modPersonas->setRelation(modPersonas->fieldIndex("tipo"), QSqlRelation("tbTipo", "id", "tipo"));
modPersonas->select();
//filtro de busquedas
proxyPersonas = new QSortFilterProxyModel(this);
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
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)