View Full Version : subwindow mdi signal
walito
4th August 2007, 19:54
Hi.
Im learning qmdiarea, but I have problem.
What SIGNAL I need when I click buttom this do show new subwindow?
Thz.
Walter
marcel
4th August 2007, 19:57
Sorry Walter, but I don't understand your post.
Do you have a button that shows a new MDI child? If you do, and your button is a QPushButton, then clicked() is the signal you're looking for.
Otherwise please be more specific and maybe post some code.
Regards
walito
4th August 2007, 20:57
mainwindow.cpp
mainWindow::mainWindow()
{
setupUi(this);
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
setWindowTitle(tr("MDI Editor"));
connect( menubar, SIGNAL(activated(int)), this, SLOT(actionNewWindow()) );
}
void mainWindow::actionNewWindow()
{
QMdiSubWindow *subWindow1 = new QMdiSubWindow;
subWindow1->setWindowTitle(tr("ZZZZ"));
subWindow1->setAttribute(Qt::WA_DeleteOnClose);
mdiArea->addSubWindow(subWindow1);
}
I have this code, but I can do this SIGNAL? I have no error but no nothing to display. :(
Well, Thz marcel!! :cool:
marcel
4th August 2007, 21:02
But you got it all wrong...
The menu bar is just the container for window menus.
These menus contain in turn menu items(actions).
What you have to do is create a menu and add an action to it( called New Window, if you will).
Then connect it's triggered signal to your slot.
For a detailed example, see the Menus example( Main Windows section) in the Qt Demos.
Regards
walito
4th August 2007, 22:44
THz, I have read de source code for this example MENUS:
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
I changed this in my code, but nothing.
connect(menubar, SIGNAL(triggered()), this, SLOT(actionNewWindow()));
or
connect(menuFile, SIGNAL(triggered()), this, SLOT(actionNewWindow()));
Any way, I not understand, but no problem.
Thz
marcel
4th August 2007, 23:06
I think the only solution is to post the entire code and have someone look at it.
Regards
walito
5th August 2007, 01:10
Ok attach the project.
:crying:
Thz
marcel
5th August 2007, 16:59
Here's the corrected source:
#include <QtGui>
#include "mainwindow.h"
ventanaPrincipal::ventanaPrincipal()
{
setupUi(this);
mdiArea = new QMdiArea(this);
setCentralWidget(mdiArea);
setWindowTitle(tr("MDI Editor"));
setMinimumSize(160, 160);
resize(480, 320);
connect(actionNueva_ventana, SIGNAL(triggered()), this, SLOT(nueva_ventana()));
}
void ventanaPrincipal::nueva_ventana()
{
QMdiSubWindow *subWindow1 = new QMdiSubWindow(this);
subWindow1->setWindowTitle(tr("ZZZZ"));
subWindow1->setAttribute(Qt::WA_DeleteOnClose);
subWindow1->setWidget(new QPushButton("xxx"));
mdiArea->addSubWindow(subWindow1);
subWindow1->show();
}
Your mistake is actually that you do not exactly know what it means to create menus with the designer.
The designer adds a menu action for every menu item that you create. The action is named after the menu item.
In your case, for the new window menu item you got the action actionNueva_ventana which was created automatically created for you.
This happens with all menu items.
I modified the slot name in order to make an explicit connect.
Take a good look at ui_uimain.h( generated by UIC from your UI file). Try to make the (logical)connections between what is in there and what you created in the UI.
Regards
walito
5th August 2007, 23:15
Thz for your help!!
Now understand! In the Signal/Slot Editor (In designer) I created the connection:
QObject::connect(actionNueva_ventana, SIGNAL(triggered()), vPrincipal, SLOT(actionNueva_ventana()));
Now work.
Well thz, and attach project for future people need this example.
Bye bye
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.