PDA

View Full Version : Qt 5.2 and QWeakPointer error: no match for 'operator='



jiveaxe
25th January 2014, 10:27
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:


m_mainWindow = new MainWindow();

where m_mainWindow is:


QWeakPointer<MainWindow> m_mainWindow;

and this is MainWindow:

mainwindow.h


//...
namespace Ui {
class MainWindow;
}

class MainWindow;

namespace The {
MainWindow* mainWindow();
}

class MainWindow : public QMainWindow
{
Q_OBJECT
friend MainWindow* The::mainWindow();

public:
explicit MainWindow(QWidget *parent = 0);
virtual ~MainWindow();
//...
};


mainwindow.cpp



QWeakPointer<MainWindow> MainWindow::s_instance;

namespace The {
MainWindow* mainWindow() { return MainWindow::s_instance.data(); }
}

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui_(new Ui::MainWindow)
{
//...
}


Anything changed in Qt 5.2 regarding QWeakPointer?

Regards

anda_skoa
25th January 2014, 11:08
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,
_

ChrisW67
26th January 2014, 04:55
QWeakPointer taking a QObject* was marked deprecated in Qt 5.0 and obsolete in 5.1

The long history: Continue using QPointer (http://www.macieira.org/blog/2012/07/continue-using-qpointer/)

jiveaxe
29th January 2014, 14:23
Thank you both