PDA

View Full Version : Opening form



jtmurphree
9th August 2011, 01:24
I am new to qt and I am wondering how to open a form from the menu bar of another form. Basically what I want to do is allow the user to click on a menu item and open up a window. I have created a function in the code that looks like this.



void MainWindow::openNets()
{
netWindow n;
n.show();
}


I have defined this function as a slot and configured the triggered signal of the menu action to that slot. However, this is not working. Can anyone point me toward the proper way to do this?

Santosh Reddy
9th August 2011, 02:33
First check if your slot is being called, i.e. have you made the connection properly?

If the slot is being called, then modify the slot like this, creating a widget on the stack will show it and delete it even before you can see it. Widget has to created on heap, like this.


void MainWindow::openNets()
{
netWindow * n = new netWindow(this); //Also do care to set a parent to newWindow class as a good Qt practice.
n->show();
}

jtmurphree
9th August 2011, 03:27
I found the problem. I did not have the function under a slots section in the header file so now I have it working but not as I would like it to. What I am working on is going to be a logging application from Amateur Radio Operators. I have a main window and a menu bar with a Nets menu. Under that menu is an action to open the nets window and I have it working. But what I would like to do is open the window when the Nets menu item is clicked. So my question now is can I make a menu item act like an action?

Dong Back Kim
10th August 2011, 02:54
Yes you need to create an action for the menu item. You can easily create actions by using Qt designer.