Passing QSqlTableModel by value



  • Hello Guys,

    How can pass a QSqlTableModel to a function by Value not by Reference?

    ERROR!

    QSqlTableModel model;
    
    foo(model);
    
    void foo(QSqlTableModel){
    ....
    }
    

    WORK BUT NOT GOOD FOR ME:

    QSqlTableModel *model;
    
    foo(*model);
    
    void foo(QSqlTableModel){
    ....
    }
    

    I do not want to use pointer for passing a "model" as it will create a reference in heap like this:

    @Qt-Champions-2016

    [Edit: Added code tags ~kshegunov]


  • Qt Champions 2017

    How can pass a QSqlTableModel to a function by Value not by Reference?

    You can't. QSqlTableModel inherits QObject which means it can't be copied, thus it can't be passed by value.

    I do not want to use pointer for passing a "model" as it will create a reference in heap like this:
    @Qt-Champions-2016

    Don't do that, please. I don't appreciate being summoned like this.


  • Moderators

    @Hasan-Vaez Why don't you want to use the heap? It is a good and useful thing.


Log in to reply
 

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