Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQueryModel return from Function outside [solved]
Forum Updated to NodeBB v4.3 + New Features

QSqlQueryModel return from Function outside [solved]

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 1.9k 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.
  • N Offline
    N Offline
    nickvan86
    wrote on last edited by
    #1

    Hello,

    i have a problem with this funktion. The Funktion load the completly Database but i dont know how can return the model

    @MainWindow main;
    QSqlQuery *qry = new QSqlQuery(main.mydb1);
    QSqlQueryModel *model = new QSqlQueryModel();
    qry->prepare("select * from "+tableName+"");
    if(qry->exec())
    {
    model->setQuery(*qry);
    }@

    When i do this in another Programm i can the Model view in tableView with ui->tableView->setModel(model) but not in a function outside from the code. Or can i set the tableView in the function?
    I hope my englisch is good to understand my problem.

    Bye

    Alex from Germany

    Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      Well, if i understand you correctly this is more c++ question. As a solution you can pass to the function pointer to you model which is outside from function:
      @bool loadDb(QSqlQueryModel *model)
      {
      //load your database
      }@

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nickvan86
        wrote on last edited by
        #3

        Hello;

        thank you for the help. That was the right solution.

        Thank you for it

        Bye

        Alex from Germany

        Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          You’re welcome !
          Also can you please update the thread title prepending [solved] so other forum users may know a solution has been found.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nickvan86
            wrote on last edited by
            #5

            bq. thread title prepending [solved]

            Hello, how get this? I Don´t know?

            Alex

            Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qxoz
              wrote on last edited by
              #6

              Just edit first post of this thread
              and change caption.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nickvan86
                wrote on last edited by
                #7

                Are this okay?

                Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qxoz
                  wrote on last edited by
                  #8

                  Yes ok. :)

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nickvan86
                    wrote on last edited by
                    #9

                    Supi :-)

                    Qt 5.2.1 Creator 3.0.1 Windows 7 64bit

                    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