Estimados, alguna alma caritativa que pueda pasarme un link de referencia para iniciarme con sqlite + qml.... estuve buscando en san google pero no encuentro mucha información, gracias.
Saludos,
Johan
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
viewer.rootContext()->setContextProperty("QtQuick2ApplicationViewer", &viewer);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("d:\sqlite\mibase.db");
if(!db.open())
{
//qDebug() << db.lastError();
qFatal("No conectado!");
}
else
qDebug("Conectado.");
QSqlQueryModel *someSqlModel = new QSqlQueryModel();
someSqlModel->setQuery("select nombre from alumno");
QQmlContext *context = viewer.rootContext();
context->setContextProperty("datamodel", someSqlModel);
viewer.setMainQmlFile(QStringLiteral("qml/prueba2/main.qml"));
viewer.showFullScreen();
viewer.showExpanded();
viewer.show();
return app.exec();
}
main.qml
=====================================
Rectangle {id: windowwidth: 600height: 468ListView {width: 200; height: 200model: datamodeldelegate: Row {Rectangle {width: 100; height: 40Text {anchors.fill: parenttext: display}
}
}
}
}Mi problema en este caso, es que los datos consultados por QSqlQueryModel y QQmlContext
--Has recibido este mensaje porque estás suscrito al grupo "Qt-español" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus correos electrónicos, envía un correo electrónico a qt-espanol+...@googlegroups.com.
Para publicar una entrada en este grupo, envía un correo electrónico a qt-es...@googlegroups.com.
Visita este grupo en http://groups.google.com/group/qt-espanol.
Para obtener más opciones, visita https://groups.google.com/groups/opt_out.
These databases are user-specific and QML-specific, but accessible to all QML applications. They are stored in the Databases subdirectory of QQmlEngine::offlineStoragePath(), currently as SQLite databases.
Database connections are automatically closed during Javascript garbage collection.
Ten en cuenta que solo tienes que pasar el nombre de la base de datos, no el nombre del fichero.
Para pasarle el path usa la siguiente línea#include <QQmlComponent>
ó #include <QtQml/QQmlContext>
error: variable 'QQmlComponent component' has initializer but incomplete type
QQmlComponent component(&engine, QUrl::fromLocalFile("qml/untitled3/main.qml"));
^
# Add more folders to ship with the application, here
folder_01.source = qml/untitled3
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += \
message.h
#ifndef MESSAGE_H
#define MESSAGE_H
#include <QObject>
class Message : public QObject
{
Q_OBJECT
Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
public:
void setAuthor(const QString &a) {
if (a != m_author) {
m_author = a;
emit authorChanged();
}
}
QString author() const {
return m_author;
}
signals:
void authorChanged();
private:
QString m_author;
};
#endif
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlContext>
#include <QQmlEngine>
#include <QQmlComponent>
#include "message.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlEngine *engine = new QQmlEngine;
Message msg;
engine->rootContext()->setContextProperty("msg", &msg);
QQmlComponent component(&engine, QUrl::fromLocalFile("qml/untitled3/main.qml"));
component.create();
return app.exec();
}