PDA

View Full Version : QMidiSubwindow, addSubwindow using QsharedPointer



Speerfish
21st March 2014, 10:35
Hello everybody,
for my program i use Qsubwindow
i did write a panel class with inherits QMidiSubwindow


class MainWindow;

class panel : public QMdiSubWindow
{
Q_OBJECT
public:
panel(QPoint Position,QPoint Dimension); /**Constructor*/
~panel(); /**Destructor*/
private:

protected:
};

#endif // PANEL_H

in my mainwindow.h i did create a sharePointer of the panel class


class MainWindow : public QMainWindow, public grahicsEnum{
Q_OBJECT
public:
MainWindow();
~MainWindow();
protected:
void closeEvent(QCloseEvent *event);
void changeEvent(QEvent *event);
bool eventFilter(QObject *obj, QEvent *event);

private slots:

signals:

private:
QSharedPointer<panel> mypanel;
panel *MyTest;

};

and in the mainwindow.cpp


MainWindow::MainWindow(){
//show the application in full screen mode
showFullScreen();
//Window stays on top at any time
setWindowFlags(Qt::WindowStaysOnTopHint);
QMdiArea* area = new QMdiArea();
//set the policy for the application
area->setSizePolicy(QSizePolicy::Expanding,QSizePolicy:: Expanding);
//create all the panel instances

MyTest = new panel(QPoint(400,600), //Position
QPoint(1000,100));//Dimension

mypanel = QSharedPointer<panel>(new panel(QPoint(400,600),QPoint(100,100)));

area->addSubWindow(MyTest); // works perfectly
area->addSubWindow(mypanel); // does not work

add Subwindow expects a pointer to QWidget, how can i use a tempalte here.
......
Help is appreciated..

anda_skoa
21st March 2014, 13:38
I don't think it is wise to put a widget into a QSharedPointer and give it a parent. This will only work if the QSharedPointer deletes first.
In your case you have to guarantee that MainWindow is destroyed before the QMdiArea instance is.

Any specific reason why you wanted to use a QSharedPointer here in the first place?

Anyway, the answer to your question is QSharedPointer::data()

Cheers,
_