Let me provide example of what I'm trying to do.
// addressbook.cpp
AddressBook
::AddressBook(QObject *parent
) :{
setQuery("select * from person");
setHeaderData
(0, Qt
::Horizontal,
QObject::tr("ID"));
setHeaderData
(1, Qt
::Horizontal,
QObject::tr("firstName"));
setHeaderData
(2, Qt
::Horizontal,
QObject::tr("lastName"));
}
// main.cpp
int main(int argc, char *argv[]) {
// ...
AddressBook addressBook;
rootContex->setContextProperty("addressBook", &addressBook);
// ...
}
// main.qml
import Qt 4.7
Rectangle {
// ...
ListView {
id: list
anchors.fill: parent
model: addressBook
delegate: Item {
Column {
Text {
text: firstname
}
Text {
text: lastName
}
}
}
}
}
// addressbook.cpp
AddressBook::AddressBook(QObject *parent) :
QSqlQueryModel(parent)
{
setQuery("select * from person");
setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
setHeaderData(1, Qt::Horizontal, QObject::tr("firstName"));
setHeaderData(2, Qt::Horizontal, QObject::tr("lastName"));
}
// main.cpp
int main(int argc, char *argv[]) {
// ...
AddressBook addressBook;
rootContex->setContextProperty("addressBook", &addressBook);
// ...
}
// main.qml
import Qt 4.7
Rectangle {
// ...
ListView {
id: list
anchors.fill: parent
model: addressBook
delegate: Item {
Column {
Text {
text: firstname
}
Text {
text: lastName
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks