QSqlQueryModel return from Function outside [solved]

  • 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+"");

    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.


    Alex from Germany

  • 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

  • Hello;

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

    Thank you for it


    Alex from Germany

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

  • bq. thread title prepending [solved]

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


  • Just edit first post of this thread
    and change caption.

  • Are this okay?

  • Yes ok. :)

  • Supi :-)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.