I got it working! You were right, after some more testing, it turned out, that my class was deleted after QApplication was already deleted. That's what I'm using now:
// shared_window.h
#ifndef SHARED_WINDOW_H
#define SHARED_WINDOW_H
#include <QObject>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QMainWindow>
class ROBOTCORE_EXPORT SharedWindow : public QObject
{
Q_OBJECT
// Singleton
Q_DISABLE_COPY(SharedWindow)
public:
~SharedWindow();
static SharedWindow *instance(void);
private:
QMdiArea *mdi;
static SharedWindow *inst;
QMainWindow *wnd;
// Singleton
SharedWindow();
private slots:
void cleanup(void);
};
#endif // SHARED_WINDOW_H
// shared_window.cpp
#include "shared_window.h"
SharedWindow *SharedWindow::inst = nullptr;
SharedWindow::SharedWindow()
{
this->wnd = new QMainWindow();
this->mdi = new QMdiArea();
this->wnd->setCentralWidget(this->mdi);
this->mdi->addSubWindow(new QSlider());
this->wnd->show();
}
void SharedWindow::cleanup()
{
delete this->wnd;
}
SharedWindow::~SharedWindow()
{
}
SharedWindow *SharedWindow::instance()
{
if(SharedWindow::inst == nullptr)
{
SharedWindow::inst = new SharedWindow();
// Setting qApp as the parent won't do it, don't know why
connect(QApplication::instance(), &QApplication::aboutToQuit,
SharedWindow::inst, &SharedWindow::cleanup);
}
return SharedWindow::inst;
}
I couldn't delete it from the main application, because I have no control over the main application. Also, my shared window is only used by some specific plugins and isn't part of the main project. The main application has a window of it's own.
Thanks!