View Full Version : QMdiArea problem
walito
29th July 2007, 23:33
Hi, people, it's my firt post.
Im newbie, and Im problem with QMdiArea.
MdiChild::MdiChild()
{
setAttribute(Qt::WA_DeleteOnClose);
isUntitled = true;
}
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
MdiChild *child = new MdiChild;
mdiArea.addSubWindow(child);
//mdiArea->addSubWindow(child);
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
marcel
29th July 2007, 23:40
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
walito
30th July 2007, 02:37
Sorry, The code is:
main.c
#include <QApplication>
#include "mdiwindow.h"
#include "main.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MiMDI *ventana;
ventana = new MiMDI;
ventana->show();
return app.exec();
}
mdiwindow.cpp
#include <QtGui>
#include <QMdiArea>
#include "mdiwindow.h"
#include "childwindow.h"
MiMDI::MiMDI(QWidget *parent)
{
//setupUi(this);
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
setWindowTitle(tr("MDI Editor"));
connect( menuArchivo, SIGNAL(activated(int)), this, SLOT(actionSalir()) );
}
void MiMDI::actionSalir()
{
MdiChild *child = new MdiChild;
mdiArea.addSubWindow(child);
//child->show();
}
mdiwindow.h
#ifndef __MDIWINDOW_H__
#define __MDIWINDOW_H__
#include <QMdiArea>
#include "ui_mdi.h"
//class QMdiArea;
class MiMDI : public QMainWindow, private Ui::VentanaPrincipal
{
Q_OBJECT
public:
MiMDI(QWidget *parent = 0);
public slots:
void actionSalir();
private:
QMdiArea *mdiArea;
};
#endif // __MDIWINDOW_H__
childwindow.cpp
#include <QtGui>
#include "childwindow.h"
MdiChild::MdiChild()
{
setAttribute(Qt::WA_DeleteOnClose);
isUntitled = true;
}
// place your code here
chilwindow.h
#ifndef __CHILDWINDOW_H__
#define __CHILDWINDOW_H__
class MdiChild
{
Q_OBJECT
public:
MdiChild();
};
#endif // __CHILDWINDOW_H__
It's all.
Im used -> but the error is:
no matching function for call to QMdiArea::addSubWindow(MdhChild*&)
Thz
marcel
30th July 2007, 08:52
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:
mdiArea->addSubWindow( mdiChild );
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
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.