Results 1 to 4 of 4

Thread: initilization of QScopedPointer

  1. #1
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default initilization of QScopedPointer

    I have a empty QScopedPointer defined in a header.

    Qt Code:
    1. QScopedPointer<HardwareInterface> hwi;
    To copy to clipboard, switch view to plain text mode 

    I know that I can initilize it doing this in my class.

    Qt Code:
    1. MainClass::MainClass(QObject *parent) :
    2. QObject(parent), hwi(new HardwareInterface())
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 

    But is there another way to do it in the main-line of the code? For example maybe I need to get the values of parameters before I init it.

    I have tried this,

    Qt Code:
    1. hwi = QScopedPointer<HardwareInterface>(new HardwareInterface());
    To copy to clipboard, switch view to plain text mode 

    but I get this error:

    Qt Code:
    1. /home/trey/Qt5.2.1/5.2.1/gcc_64/include/QtCore/qglobal.h:979: error: 'QScopedPointer<T, Cleanup>& QScopedPointer<T, Cleanup>::operator=(const QScopedPointer<T, Cleanup>&) [with T = HardwareInterface; Cleanup = QScopedPointerDeleter<HardwareInterface>]' is private
    2. Class &operator=(const Class &) Q_DECL_EQ_DELETE;
    3. ^
    To copy to clipboard, switch view to plain text mode 

    whatever that means.

  2. #2
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: initilization of QScopedPointer

    You can set the pointer after initialization using the reset method.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: initilization of QScopedPointer

    Or use a QSharedPointer.

    Cheers,
    _

  4. #4
    Join Date
    Nov 2009
    Posts
    68
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded

    Default Re: initilization of QScopedPointer

    thanks!

    I guess I should of looked for something that took a pointer and returned a QScopedPointer.

Similar Threads

  1. How to mix QScopedPointer with QPointer
    By jezz in forum Qt Programming
    Replies: 5
    Last Post: 14th April 2012, 08:20
  2. Replies: 0
    Last Post: 22nd June 2010, 20:27

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
  •  
Qt is a trademark of The Qt Company.