Sadly that isnt the problem. Yes, the Q_OBJECT macro is there.
I have created a minimal demo to reproduce the issue:
{
Q_OBJECT
public:
{}
int a,b,c;
};
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0) {
my_wid* mm = create_mywid();
delete mm;
}
my_wid
* create_mywid
(QWidget* parent
=0) {
my_wid* w = new my_wid(parent);
connect(w, &QObject::destroyed, this, &MainWindow::remove_mywid);
return w;
}
protected slots:
void remove_mywid
(QObject* removed
) {
my_wid* test = qobject_cast<my_wid*>(removed);
qDebug() << test; // is 0 :(
}
};
class my_wid : public QWidget
{
Q_OBJECT
public:
my_wid(QWidget* p=0) : QWidget(p)
{}
int a,b,c;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0)
{
my_wid* mm = create_mywid();
delete mm;
}
my_wid* create_mywid(QWidget* parent=0)
{
my_wid* w = new my_wid(parent);
connect(w, &QObject::destroyed, this, &MainWindow::remove_mywid);
return w;
}
protected slots:
void remove_mywid(QObject* removed)
{
my_wid* test = qobject_cast<my_wid*>(removed);
qDebug() << test; // is 0 :(
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks