Results 1 to 3 of 3

Thread: How to return QtListWidget from function

  1. #1
    Join Date
    Mar 2016
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

    Default How to return QtListWidget from function

    I am looking to create a QListWidget in a function and then return it. I get this error: main.cpp:112: error: could not convert 'lw' from 'QListWidget*' to 'QListWidget' return lw;
    ^

    my function:

    header:
    Qt Code:
    1. private slots:
    2. QListWidget create();
    To copy to clipboard, switch view to plain text mode 


    cpp
    Qt Code:
    1. QListWidget Main::create(){
    2.  
    3.  
    4. lw->addItem(new QListWidgetItem("one"));
    5. lw->addItem(new QListWidgetItem("two"));
    6. return lw;
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to return QtListWidget from function

    C++ ABC. lw is declared as a pointer.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to return QtListWidget from function

    And even if the syntax was fixed, it is impossible to return a QListWidget instance created on the stack since the copy constructor and assignment operator are disabled for QObject-based classes. You can only return a pointer to a QObject-based instance created on the heap.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. function to return QSQLquerymodel
    By cpuinthebrain in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2015, 12:12
  2. Replies: 1
    Last Post: 2nd January 2013, 09:48
  3. How to return QString from function
    By Rondle in forum Newbie
    Replies: 3
    Last Post: 21st November 2012, 18:51
  4. Replies: 4
    Last Post: 2nd April 2010, 10:04
  5. Function return
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2009, 00:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.