Results 1 to 4 of 4

Thread: Qt 5.2 and QWeakPointer error: no match for 'operator='

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt 5.2 and QWeakPointer error: no match for 'operator='

    Hi,
    I'm porting my qt4 application to qt5. While it compiled successfully in qt 5.1 (if I'm not wrong), with version 5.2 I got the following compile error:

    no match for ‘operator=’ (operand types are ‘QWeakPointer<MainWindow>’ and ‘MainWindow*’)
    The error is triggered at this line:

    Qt Code:
    1. m_mainWindow = new MainWindow();
    To copy to clipboard, switch view to plain text mode 

    where m_mainWindow is:

    Qt Code:
    1. QWeakPointer<MainWindow> m_mainWindow;
    To copy to clipboard, switch view to plain text mode 

    and this is MainWindow:

    mainwindow.h

    Qt Code:
    1. //...
    2. namespace Ui {
    3. class MainWindow;
    4. }
    5.  
    6. class MainWindow;
    7.  
    8. namespace The {
    9. MainWindow* mainWindow();
    10. }
    11.  
    12. class MainWindow : public QMainWindow
    13. {
    14. Q_OBJECT
    15. friend MainWindow* The::mainWindow();
    16.  
    17. public:
    18. explicit MainWindow(QWidget *parent = 0);
    19. virtual ~MainWindow();
    20. //...
    21. };
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp

    Qt Code:
    1. QWeakPointer<MainWindow> MainWindow::s_instance;
    2.  
    3. namespace The {
    4. MainWindow* mainWindow() { return MainWindow::s_instance.data(); }
    5. }
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui_(new Ui::MainWindow)
    10. {
    11. //...
    12. }
    To copy to clipboard, switch view to plain text mode 

    Anything changed in Qt 5.2 regarding QWeakPointer?

    Regards
    Giuseppe CalÃ

  2. #2
    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: Qt 5.2 and QWeakPointer error: no match for 'operator='

    If you are using QWeakPointer to track the window's life time, i.e. get the pointer reset to 0 when the window is deleted, then use QPointer instead.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    jiveaxe (29th January 2014)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt 5.2 and QWeakPointer error: no match for 'operator='

    QWeakPointer taking a QObject* was marked deprecated in Qt 5.0 and obsolete in 5.1

    The long history: Continue using QPointer

  5. The following user says thank you to ChrisW67 for this useful post:

    jiveaxe (29th January 2014)

  6. #4
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt 5.2 and QWeakPointer error: no match for 'operator='

    Thank you both
    Giuseppe CalÃ

Similar Threads

  1. no match fo 'operator[]='
    By jeff28 in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2012, 09:53
  2. Error: No match for call to '(QPoint)()'
    By GT Development in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2011, 08:24
  3. QPainter error: no match for call ...
    By tonnot in forum Newbie
    Replies: 2
    Last Post: 7th October 2010, 12:00
  4. no match for 'operator=' in...
    By toss in forum Newbie
    Replies: 2
    Last Post: 14th April 2010, 00:08
  5. No match for operator>>
    By Salazaar in forum Newbie
    Replies: 18
    Last Post: 12th June 2007, 17:48

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.