<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[qmlRegisterType sqlquerylmodel (subclass) not show on tableView]]></title><description><![CDATA[<p dir="auto">I use these sample for connect my sqlite db with tableview in qml quick 2 .... my ui.qml file import table view in these way:</p>
<pre><code>import QtQuick 2.3
import QtQuick.Controls 2.3
import QtQuick.Controls 1.4 as C
import QtDataVisualization 1.3
import QtQuick.LocalStorage 2.0
import QtQuick.Window 2.10

/* some code */

               C.TableView{
                           id: tableViewXX


</code></pre>
<p dir="auto">for create sqlmodeldata I subclass it as explained in these <a href="https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML" target="_blank" rel="noopener noreferrer nofollow ugc">wiki</a> (last example) ... so I would to create a qmlregisterType for use it in some ui.qml page with tableView .... is right these or one time that my newSqlModelData1 and newSqlModelData2 I can use it witouth register and import it?</p>
<p dir="auto">regards</p>
]]></description><link>https://forum.qt.io/topic/100264/qmlregistertype-sqlquerylmodel-subclass-not-show-on-tableview</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 03:37:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/100264.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 01 Mar 2019 16:10:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to qmlRegisterType sqlquerylmodel (subclass) not show on tableView on Mon, 04 Mar 2019 19:19:48 GMT]]></title><description><![CDATA[<p dir="auto">I answer myself:</p>
<ul>
<li>basically I not know qml quick world ... but the solution is not abstractmodel but the right setting of context.</li>
</ul>
<p dir="auto">so my new main code (working) is these:</p>
<pre><code>#include &lt;QGuiApplication&gt;
#include &lt;QQmlApplicationEngine&gt;
#include &lt;QtQuickControls2&gt;
#include &lt;QtSql&gt;
#include &lt;QtGui/QGuiApplication&gt;
#include &lt;QtCore/QDir&gt;
#include &lt;QtQuick/QQuickView&gt;
#include &lt;QtQml/QQmlEngine&gt;
#include &lt;QtQml/qqml.h&gt;
#include "shared/shared.h"
#include &lt;QtCharts&gt;
#include &lt;QtDataVisualization&gt;
#include &lt;QAbstractTableModel&gt;
#include &lt;QtMessageHandler&gt;
#include &lt;QMessageBox&gt;
#include &lt;QMessageLogContext&gt;
#include &lt;QMessageLogger&gt;
#include &lt;QDebug&gt;
#include &lt;QQmlEngine&gt;
#include "sqlquerymodel.h"


using namespace QtCharts;

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

   QGuiApplication app(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("/home/pc/Qt/TestApp/DataBase/TestAnalyticsDB");
    if(db.open()) {//{ QMessageBox::information(nullptr,"Ok","Connection ok");
        qDebug() &lt;&lt; "connessione ok";
    }
    else qDebug() &lt;&lt; "connessione FALLITA";//QMessageBox::information(nullptr,"Error","some error.");


    SqlQueryModel *UserRegistry = new SqlQueryModel(nullptr);
    UserRegistry-&gt;setQuery("SELECT * FROM userData");
    SqlQueryModel *AdmRegistry = new SqlQueryModel(nullptr);
    AdmRegistry-&gt;setQuery("SELECT * FROM admData");


    QQmlApplicationEngine engine;
    engine.rootContext()-&gt;setContextProperty("userModel", UserRegistry);  /* the trick */
    engine.rootContext()-&gt;setContextProperty("admModel", AdmRegistry);  /* second query table model */
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;


    return app.exec();
}
</code></pre>
<p dir="auto">after these in ui.qml part in tableView section is simple to write these :</p>
<pre><code>import QtQuick 2.3
import QtQuick.Controls 2.3
import QtQuick.Controls 1.4 as C

/*some code*/
 C.TableView {
                        id: tableViewUser
                        x: 8
                        y: 8
                        width: 1152
                        height: 244
                        anchors.right: parent.right
                        anchors.left: parent.left
                        anchors.top: parent.top
                        verticalScrollBarPolicy: 2
                        clip: true

                        model: userModel     /* the trick */

                        C.TableViewColumn {
                            title: "User id"
                            role: "IDuser"
                            width: title.length * 10
                            visible: true
                        }

/* other column*/
/* second table*/

                    C.TableView {
                        id: tableViewData
                        x: 0
                        y: 250
                        width: 1168
                        height: 433
                        anchors.right: parent.right
                        anchors.left: parent.left
                        anchors.top: parent.bottom
                        verticalScrollBarPolicy: 2
                        clip: true

                        model: admModel   /* second query table model */

                        C.TableViewColumn {
                            title: "Sensore 1"
                            role: "sens1"
                            width: title.length * 15
                        }
</code></pre>
<p dir="auto">with SqlQueryModel class i symple to show every type of query in a table (in these case in quick 1.4 near to 2.3 control, but I think is the same with new TableView in Qt5.12).</p>
<p dir="auto">regards</p>
]]></description><link>https://forum.qt.io/post/515238</link><guid isPermaLink="true">https://forum.qt.io/post/515238</guid><dc:creator><![CDATA[gfxx]]></dc:creator><pubDate>Mon, 04 Mar 2019 19:19:48 GMT</pubDate></item><item><title><![CDATA[Reply to qmlRegisterType sqlquerylmodel (subclass) not show on tableView on Sat, 02 Mar 2019 07:58:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gfxx">@<bdi>gfxx</bdi></a> actually I insert my</p>
<pre><code>model: SqlQueryModel
</code></pre>
<p dir="auto">in my page and print the table in these way :</p>
<pre><code>import QtQuick 2.3
import QtQuick.Controls 2.3
import QtQuick.Controls 1.4 as C
import QtDataVisualization 1.3
import QtQuick.LocalStorage 2.0
import QtQuick.Window 2.10
import QtSensors 5.9
import Qt.labs.calendar 1.0
import QtGraphicalEffects 1.0
import QtQuick.Controls.Imagine 2.3
import QtQuick.Extras 1.4
import QtQuick.XmlListModel 2.0
import QtQml.Models 2.1
import QtCharts 2.0
import QtQuick.Layouts 1.1
import userRegistry 1.0

/* some code about layout */


                   C.TableView {
                        id: tableViewUser
                        x: 8
                        y: 8
                        width: 1152
                        height: 675
                        verticalScrollBarPolicy: 2
                        anchors.fill: parent
                        clip: true

                        C.TableViewColumn {
                            title: "User id"
                            role: "IDuser"
                        }
                        C.TableViewColumn {
                            title: "Nome"
                            role: "nome"
                        }
                        C.TableViewColumn {
                            title: "Cognome"
                            role: "Cognome"
                        }
                        C.TableViewColumn {
                            title: "Data di Nascita"
                            role: "nascita"
                        }
                        C.TableViewColumn {
                            title: "Comune di Provenienza"
                            role: "localita"
                        }

                        model: SqlQueryModel


                    }
                }
</code></pre>
<p dir="auto">where my query if "SELECT * FROM userData"  where IDuser, nome, Cognome, nascita and localita is the name of DB table column .... i try to make these query for debug all works ok ... but when I use model in qml file the TableView show empty row and cell ....</p>
<p dir="auto">in my main.cpp i use sqlquerymodel subclassed in these way:</p>
<pre><code>    SqlQueryModel *userData = new SqlQueryModel(nullptr);
    userData-&gt;setQuery("SELECT * FROM userData");

    qmlRegisterType&lt;SqlQueryModel&gt;("userRegistry", 1, 0, "SqlQueryModel");
</code></pre>
<p dir="auto">someone can help me about these ??</p>
<p dir="auto">regards</p>
]]></description><link>https://forum.qt.io/post/514944</link><guid isPermaLink="true">https://forum.qt.io/post/514944</guid><dc:creator><![CDATA[gfxx]]></dc:creator><pubDate>Sat, 02 Mar 2019 07:58:57 GMT</pubDate></item></channel></rss>