Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Columns in a table
Forum Updated to NodeBB v4.3 + New Features

Columns in a table

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giammarco
    wrote on last edited by
    #1

    Hallo,
    I am new at using QML and I am trying to count the columns of a table from a database but I don't know how to do it, I have tried to import a js with the row:

    @
    cols = document.getElementById('myTableName').rows[0].cells.length;
    @

    but QtCreator gives me an error : "ReferenceError: Can't find variable: document".
    So, how can I find the number of columns of a table from an opened database?
    Thank you,
    Giammarco

    [EDIT: code formatting, Volker]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      You are not showing enough code. Foremost, you don't show us where that document variable is supposed to come from.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Seba84
        wrote on last edited by
        #3

        Giammarco,
        I agree with Andre, you should post some more code, otherwise we don't understand the error. How is "document" defined?

        I have already worked on a project using Qt and Sql, here you have a synthetic example from my program (maybe it helps):

        @// OPEN DATABASE CONNECTION
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName(fileName);
        if(!db.open())
        ErrorMessage();

        // MAKES QUERY (hope you know sql)
        QSqlQueryModel *model_query = new QSqlQueryModel(this);
        model_query->setQuery("SELECT * FROM myTableName", db);

        // GENERIC LOOP TO GO THROUGHT ALL THE ELEMENTS ON THE TABLE
        for(int i=0; i<model_query->rowCount(); i++) {
        for(int j=0; j<model_query->columnCount(); j++) {
        (...)
        }
        }@

        You can see on the for loop that I used the functions:
        @int QSqlQueryModel::rowCount()
        int QSqlQueryModel::columnCount()@

        Cheers!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved