Hi all,
I get a weird error message when i create a view with concatenate function and link it against a QTableView. My qt code works when i link QTableView with the same view with out concatenation.
//Sqlite side:
bool Database
::safeQueryExec(QString query
) {
bool ret = true;
if(!q.exec(query))
{
ret = false;
qDebug() << "*** Database::safeQueryExec: query fallita: " << query << q.lastError().text();
}
return ret;
}
if(!safeQueryExec("CREATE TABLE persone (idpersona integer primary key autoincrement, firstname varchar(20) NOT NULL,lastname varchar(20) NOT NULL, dtna date,codfisc varchar(16) UNIQUE, piva varchar(11) UNIQUE,ragsoc varchar(40) UNIQUE,cellphone varchar(30), workphone varchar(30), email varchar(30), isdipendente int references dipendente(iddipendente),isfornitore int references fornitore(idfornitore), iscondomino int references condomino(idcondomino))"))
return false;
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
/* working view:
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
*/
//widgets side:
m_afferenzeviewmodel->setTable("vafferenze");
ui->tvProprieta->setModel(m_afferenzeviewmodel);
ui->tvProprieta->horizontalHeader()->setStretchLastSection(true);
m_afferenzeviewmodel->setFilter("idtipo = 1");
m_afferenzeviewmodel->select();
//Sqlite side:
bool Database::safeQueryExec(QString query)
{
bool ret = true;
QSqlQuery q;
if(!q.exec(query))
{
ret = false;
qDebug() << "*** Database::safeQueryExec: query fallita: " << query << q.lastError().text();
}
return ret;
}
if(!safeQueryExec("CREATE TABLE persone (idpersona integer primary key autoincrement, firstname varchar(20) NOT NULL,lastname varchar(20) NOT NULL, dtna date,codfisc varchar(16) UNIQUE, piva varchar(11) UNIQUE,ragsoc varchar(40) UNIQUE,cellphone varchar(30), workphone varchar(30), email varchar(30), isdipendente int references dipendente(iddipendente),isfornitore int references fornitore(idfornitore), iscondomino int references condomino(idcondomino))"))
return false;
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
/* working view:
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
*/
//widgets side:
m_afferenzeviewmodel = new QSqlTableModel(this);
m_afferenzeviewmodel->setTable("vafferenze");
ui->tvProprieta->setModel(m_afferenzeviewmodel);
ui->tvProprieta->horizontalHeader()->setStretchLastSection(true);
m_afferenzeviewmodel->setFilter("idtipo = 1");
m_afferenzeviewmodel->select();
To copy to clipboard, switch view to plain text mode
this is the error message:
ASSERT: "idx >= 0 && idx < s" in file ../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
ASSERT: "idx >= 0 && idx < s" in file ../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
To copy to clipboard, switch view to plain text mode
I suppose that QTableView rely on columns number so using concatenate function make a mess somewhere.
But i need to show lastname and firstname of a person into a single cell of QTableView. As it manage insertion,
modify and delete of a relation table. So i need that data about persons are displayed as "name+surname" while
on db it's managed as the person id. I tried using QSqlRelationalTableModel too, but i doesn't fix my needs for
several reasons:
- idpersona is part of afferenze table so i can't use it,
- i need to show two table fields (firstname, and lastname) into a single QTableView's cell. While QSqlRelationalTable allow only one-to-one relation.
I hope to be clear even if my english sucks 
thanks in advance.
Hi all,
I get a weird error message when i create a view with concatenate function and link it against a QTableView. My qt code works when i link QTableView with the same view with out concatenation.
//Sqlite side:
bool Database
::safeQueryExec(QString query
) {
bool ret = true;
if(!q.exec(query))
{
ret = false;
qDebug() << "*** Database::safeQueryExec: query fallita: " << query << q.lastError().text();
}
return ret;
}
if(!safeQueryExec("CREATE TABLE persone (idpersona integer primary key autoincrement, firstname varchar(20) NOT NULL,lastname varchar(20) NOT NULL, dtna date,codfisc varchar(16) UNIQUE, piva varchar(11) UNIQUE,ragsoc varchar(40) UNIQUE,cellphone varchar(30), workphone varchar(30), email varchar(30), isdipendente int references dipendente(iddipendente),isfornitore int references fornitore(idfornitore), iscondomino int references condomino(idcondomino))"))
return false;
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
/* working view:
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
*/
//widgets side:
m_afferenzeviewmodel->setTable("vafferenze");
ui->tvProprieta->setModel(m_afferenzeviewmodel);
ui->tvProprieta->horizontalHeader()->setStretchLastSection(true);
m_afferenzeviewmodel->setFilter("idtipo = 1");
m_afferenzeviewmodel->select();
//Sqlite side:
bool Database::safeQueryExec(QString query)
{
bool ret = true;
QSqlQuery q;
if(!q.exec(query))
{
ret = false;
qDebug() << "*** Database::safeQueryExec: query fallita: " << query << q.lastError().text();
}
return ret;
}
if(!safeQueryExec("CREATE TABLE persone (idpersona integer primary key autoincrement, firstname varchar(20) NOT NULL,lastname varchar(20) NOT NULL, dtna date,codfisc varchar(16) UNIQUE, piva varchar(11) UNIQUE,ragsoc varchar(40) UNIQUE,cellphone varchar(30), workphone varchar(30), email varchar(30), isdipendente int references dipendente(iddipendente),isfornitore int references fornitore(idfornitore), iscondomino int references condomino(idcondomino))"))
return false;
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
/* working view:
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname,a.idafferenza,a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
*/
//widgets side:
m_afferenzeviewmodel = new QSqlTableModel(this);
m_afferenzeviewmodel->setTable("vafferenze");
ui->tvProprieta->setModel(m_afferenzeviewmodel);
ui->tvProprieta->horizontalHeader()->setStretchLastSection(true);
m_afferenzeviewmodel->setFilter("idtipo = 1");
m_afferenzeviewmodel->select();
To copy to clipboard, switch view to plain text mode
this is the error message:
ASSERT: "idx >= 0 && idx < s" in file ../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
ASSERT: "idx >= 0 && idx < s" in file ../../include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
To copy to clipboard, switch view to plain text mode
I suppose that QTableView rely on columns number so using concatenate function make a mess somewhere.
But i need to show lastname and firstname of a person into a single cell of QTableView. As it manage insertion,
modify and delete of a relation table. So i need that data about persons are displayed as "name+surname" while
on db it's managed as the person id. I tried using QSqlRelationalTableModel too, but i doesn't fix my needs for
several reasons:
- idpersona is part of afferenze table so i can't use it,
- i need to show two table fields (firstname, and lastname) into a single QTableView's cell. While QSqlRelationalTable allow only one-to-one relation.
I hope to be clear even if my english sucks 
thanks in advance.
Added after 41 minutes:
i solved. Sorry for dumb question. I fond that qt make a mess if the new field doesn't have a name. So the right view is this:
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname as Condomino,a.idafferenza"
",a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,"
"a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
if(!safeQueryExec("create view vafferenze as SELECT a.idstabile,a.idscala,a.idinterno,p.lastname || ' ' || p.firstname as Condomino,a.idafferenza"
",a.idtipo,a.percentualeproprieta,a.percentualeconduzione,a.percentualenudaproprieta,"
"a.percentualeusufrutto FROM afferenze AS a JOIN persone AS p ON a.idpersona = p.idpersona"))
return false;
To copy to clipboard, switch view to plain text mode
Thanks all.
Bookmarks