Results 1 to 2 of 2

Thread: QMidiSubwindow, addSubwindow using QsharedPointer

  1. #1
    Join Date
    Dec 2013
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default QMidiSubwindow, addSubwindow using QsharedPointer

    Hello everybody,
    for my program i use Qsubwindow
    i did write a panel class with inherits QMidiSubwindow

    Qt Code:
    1. class MainWindow;
    2.  
    3. class panel : public QMdiSubWindow
    4. {
    5. Q_OBJECT
    6. public:
    7. panel(QPoint Position,QPoint Dimension); /**Constructor*/
    8. ~panel(); /**Destructor*/
    9. private:
    10.  
    11. protected:
    12. };
    13.  
    14. #endif // PANEL_H
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. class MainWindow : public QMainWindow, public grahicsEnum{
    2. Q_OBJECT
    3. public:
    4. MainWindow();
    5. ~MainWindow();
    6. protected:
    7. void closeEvent(QCloseEvent *event);
    8. void changeEvent(QEvent *event);
    9. bool eventFilter(QObject *obj, QEvent *event);
    10.  
    11. private slots:
    12.  
    13. signals:
    14.  
    15. private:
    16. QSharedPointer<panel> mypanel;
    17. panel *MyTest;
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 

    and in the mainwindow.cpp
    Qt Code:
    1. MainWindow::MainWindow(){
    2. //show the application in full screen mode
    3. showFullScreen();
    4. //Window stays on top at any time
    5. setWindowFlags(Qt::WindowStaysOnTopHint);
    6. QMdiArea* area = new QMdiArea();
    7. //set the policy for the application
    8. area->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    9. //create all the panel instances
    10.  
    11. MyTest = new panel(QPoint(400,600), //Position
    12. QPoint(1000,100));//Dimension
    13.  
    14. mypanel = QSharedPointer<panel>(new panel(QPoint(400,600),QPoint(100,100)));
    15.  
    16. area->addSubWindow(MyTest); // works perfectly
    17. area->addSubWindow(mypanel); // does not work
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QMidiSubwindow, addSubwindow using QsharedPointer

    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,
    _

Similar Threads

  1. AddSubWindow() doesn't work
    By Higgs in forum Newbie
    Replies: 4
    Last Post: 16th February 2014, 23:32
  2. Replies: 2
    Last Post: 30th January 2013, 07:05
  3. QSharedPointer / QWeakPointer in QML?
    By centipede in forum Qt Quick
    Replies: 1
    Last Post: 23rd May 2012, 10:25
  4. Replies: 2
    Last Post: 17th October 2011, 10:58
  5. Replies: 2
    Last Post: 13th May 2010, 18:46

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
  •  
Qt is a trademark of The Qt Company.