Results 1 to 4 of 4

Thread: QMdiArea problem

  1. #1
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMdiArea problem

    Hi, people, it's my firt post.
    Im newbie, and Im problem with QMdiArea.

    Qt Code:
    1. MdiChild::MdiChild()
    2. {
    3. setAttribute(Qt::WA_DeleteOnClose);
    4. isUntitled = true;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. mdiArea = new QMdiArea;
    2. setCentralWidget(mdiArea);
    3.  
    4. MdiChild *child = new MdiChild;
    5. mdiArea.addSubWindow(child);
    6. //mdiArea->addSubWindow(child);
    To copy to clipboard, switch view to plain text mode 

    anyone of the 2 options not found.
    The error is: 'addSubWindow' has not been declared.

    Im not understand, somebody help me?

    Sorry my english.
    Thz

    Walter

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea problem

    You will have to post some more code.
    One error though: mdiArea seems to be a pointer, therefore its members must be accessed with "->".

    The error could have any number of reasons.

    Also, what base class has MdiChild? Is it QMdiSubWindow? Then you should call the base class constructor in the MdiChild's constructor initializer list.

    Post the entire code, if you can.

    Regards

  3. #3
    Join Date
    Jul 2007
    Posts
    24
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea problem

    Sorry, The code is:

    main.c
    Qt Code:
    1. #include <QApplication>
    2. #include "mdiwindow.h"
    3. #include "main.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. MiMDI *ventana;
    9.  
    10. ventana = new MiMDI;
    11. ventana->show();
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    mdiwindow.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QMdiArea>
    3. #include "mdiwindow.h"
    4. #include "childwindow.h"
    5.  
    6. MiMDI::MiMDI(QWidget *parent)
    7. {
    8. //setupUi(this);
    9.  
    10. mdiArea = new QMdiArea;
    11. setCentralWidget(mdiArea);
    12. setWindowTitle(tr("MDI Editor"));
    13.  
    14. connect( menuArchivo, SIGNAL(activated(int)), this, SLOT(actionSalir()) );
    15. }
    16.  
    17. void MiMDI::actionSalir()
    18. {
    19. MdiChild *child = new MdiChild;
    20. mdiArea.addSubWindow(child);
    21. //child->show();
    22. }
    To copy to clipboard, switch view to plain text mode 

    mdiwindow.h
    Qt Code:
    1. #ifndef __MDIWINDOW_H__
    2. #define __MDIWINDOW_H__
    3.  
    4. #include <QMdiArea>
    5. #include "ui_mdi.h"
    6.  
    7. //class QMdiArea;
    8.  
    9. class MiMDI : public QMainWindow, private Ui::VentanaPrincipal
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MiMDI(QWidget *parent = 0);
    15.  
    16. public slots:
    17. void actionSalir();
    18.  
    19. private:
    20. QMdiArea *mdiArea;
    21. };
    22.  
    23. #endif // __MDIWINDOW_H__
    To copy to clipboard, switch view to plain text mode 

    childwindow.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "childwindow.h"
    3.  
    4. MdiChild::MdiChild()
    5. {
    6. setAttribute(Qt::WA_DeleteOnClose);
    7. isUntitled = true;
    8. }
    9. // place your code here
    To copy to clipboard, switch view to plain text mode 

    chilwindow.h
    Qt Code:
    1. #ifndef __CHILDWINDOW_H__
    2. #define __CHILDWINDOW_H__
    3.  
    4. class MdiChild
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. MdiChild();
    10. };
    11.  
    12. #endif // __CHILDWINDOW_H__
    To copy to clipboard, switch view to plain text mode 

    It's all.

    Im used -> but the error is:
    no matching function for call to QMdiArea::addSubWindow(MdhChild*&)

    Thz

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMdiArea problem

    First, derive MdiChild from QWidget not QObject.
    If you look at the addSubWindow function signature, it requires a QWidget, not a QObject.

    In actionSalir, mdiArea is a pointer so you need:
    Qt Code:
    1. mdiArea->addSubWindow( mdiChild );
    To copy to clipboard, switch view to plain text mode 

    The error is because there is not function addSubWindow in QMdiArea that takes a QObject(here a MdiChild|) parameter. You need a QWidget or a QWidget subclass.

    Regards

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.