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. Passing QSqlTableModel by value

Passing QSqlTableModel by value

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 713 Views 2 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.
  • Hasan VaezH Offline
    Hasan VaezH Offline
    Hasan Vaez
    wrote on last edited by kshegunov
    #1

    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]

    JKSHJ 1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3
      • Hasan VaezH Hasan Vaez

        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]

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

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

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        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