Results 1 to 4 of 4

Thread: Opening form

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Opening form

    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.

    Qt Code:
    1. void MainWindow::openNets()
    2. {
    3. netWindow n;
    4. n.show();
    5. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Opening form

    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.

    Qt Code:
    1. void MainWindow::openNets()
    2. {
    3. netWindow * n = new netWindow(this); //Also do care to set a parent to newWindow class as a good Qt practice.
    4. n->show();
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Opening form

    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?

  4. #4
    Join Date
    Aug 2011
    Location
    Seoul, Korea
    Posts
    46
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    9
    Thanked 5 Times in 5 Posts

    Default Re: Opening form

    Yes you need to create an action for the menu item. You can easily create actions by using Qt designer.
    Dong Back Kim

Similar Threads

  1. How to hide from taskbar a form showed form mainwindow
    By tonnot in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2011, 15:36
  2. Replies: 5
    Last Post: 12th March 2010, 22:43
  3. Help me to load one form over another form PushButton
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2008, 17:11
  4. Hiding a form and opening another form
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 20th February 2008, 16:04
  5. Replies: 5
    Last Post: 10th May 2006, 01:20

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.