ui = new QDeclarativeView;
QSqlQueryModel *sqlModel = new QSqlQueryModel(this);
sqlModel->setQuery("SELECT * FROM news");
QDeclarativeContext *context = ui->rootContext();
context->setContextProperty("sqlModel", sqlModel);
ListView {
anchors.fill: parent
model: sqlModel
delegate: Text {
text: title
}
}
ui->setSource(QUrl("qrc:/mainpage.qml"));
setCentralWidget(ui);
ui->setResizeMode(QDeclarativeView::SizeRootObjectToView);
qrc:/mainpage.qml:74: ReferenceError: Can't find variable: title
text: title
ArtistsSqlModel *artistsSqlModel = new ArtistsSqlModel( qApp);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("artistsModel", artistsSqlModel);
duplicate symbol __ZN12NewsSqlModel7refreshEv in:
mainwindow.o
moc_newssqlmodel.o
duplicate symbol __ZN12NewsSqlModelC2EP7QObject in:
mainwindow.o
moc_newssqlmodel.o
duplicate symbol __ZN12NewsSqlModelC1EP7QObject in:
mainwindow.o
moc_newssqlmodel.o
duplicate symbol __ZNK12NewsSqlModel4dataERK11QModelIndexi in:
mainwindow.o
moc_newssqlmodel.o
duplicate symbol __ZN12NewsSqlModel10SQL_SELECTE in:
mainwindow.o
moc_newssqlmodel.o
duplicate symbol __ZN12NewsSqlModel12COLUMN_NAMESE in:
mainwindow.o
moc_newssqlmodel.o
ld: 6 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
QHash<int, QByteArray> NewsSqlModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[ObjectRole] = "object";
return roles;
}
NewsSqlModel
он выдал ошибку, а сейчас успешно скомпилировал.NewsSqlModel *newsSqlModel = new NewsSqlModel();
qmlRegisterType<NewsSqlModel>("ru.test.test", 1, 0, "NewsSqlModel");
import QtQuick 1.0
import ru.test.test 1.0
Rectangle {
id: mainPage
width: 600
height: 400
x: 20
y: 20
NewsSqlModel {
id: newsSqlModel
}
ListView {
anchors.fill: parent
model: newsSqlModel
delegate: Text {
width: 150
height: 50
text: title
}
}
}
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("NewsSqlModel", newsSqlModel);