Results 1 to 12 of 12

Thread: Undo the this->setupId(this)

  1. #1

    Default Undo the this->setupId(this)

    Hi there,

    I'm implementing a login/logout mechanism and I have a really strange problem.

    I have created a main window with a constructor of this type:

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui_(new Ui::MainWindow)
    {
    // call a login dialog

    // the login emits a signal with the login status
    // if ok start the application and create all the interface (calling a function that does the ui_->setupUi(this); )
    }


    when the user wants to log out he goes on the logout button.
    A function that cleans everything (for the menu I use menubar()->clean() ) is called and then the login dialog is created again.
    If the user now logs, the same function that does the ui_->setupUi(this); is called but the menu actions now are not connected

    If instead of using the designer I create the menu and the actions manually, everything works.


    I have discovered that the problem is due to a "double call" to ui_->setupUi(this);

    I have also tried to put a flag and try to not to call it if the user logs in the second time, but if I don't call that function the interface will not be showed.

    I would need a function to disconnect all the actions of the menu (like a ui_->undoSetupUi(this) )

    Any hints?

    Cheers!
    Last edited by valerianst; 1st July 2013 at 10:37.

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

    Default Re: Undo the this->setupId(this)

    A simple and quick solution will be to delete MainWindow, and create a new fresh copy again.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3

    Default Re: Undo the this->setupId(this)

    Thank you for your suggestion.

    Yes, I have already thought about it but I would like to solve the real problem since it may happen again in the future...

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

    Default Re: Undo the this->setupId(this)

    I have discovered that the problem is due to a "double call" to ui_->setupUi(this);
    Calling setupUi() second time should not cause any problem.

    I would need a function to disconnect all the actions of the menu (like a ui_->undoSetupUi(this) )
    To remove all the action from menu bar use
    1. QMenuBar::clear();
    or
    2. QMainWindow::setMenuBar(new QMenuBar());
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5

    Default Re: Undo the this->setupId(this)

    Quote Originally Posted by Santosh Reddy View Post
    Calling setupUi() second time should not cause any problem.


    To remove all the action from menu bar use
    1. QMenuBar::clear();
    or
    2. QMainWindow::setMenuBar(new QMenuBar());


    Thank you again for your suggestions.

    In my case the double setupUI causes that problem. I have already tried both clear() and the QMainWindow::setMenuBar(new QMenuBar()); but it doesn't work anyway.


    Maybe the problem is something else, like the setupUI that doesn't update the UI with the correct actions..

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Undo the this->setupId(this)

    Why not just hide the main window while the login dialog is shown?
    Or disable the main window while the dialog is up?

    Cheers,
    _

  7. #7

    Default Re: Undo the this->setupId(this)

    Yes, in theory I could do that, but I think it is not the right way to solve this problem (since it might happen in the future).

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

    Default Re: Undo the this->setupId(this)

    Are there any warnings in the Application output when use logs in the second time?

    I suspect the problem is with connectSlotsByName().

    Try inhering the Ui form class instead of member variable.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Undo the this->setupId(this)

    I am with andy_skoa. Simple solution for a simple problem rather than trying to make a complex and awkward solution work.

    Another option would be to make the QMainWindow central widget a QStackedWidget with the login UI on one page and the logged in UI on the other... Then just flip between them.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  10. #10

    Default Re: Undo the this->setupId(this)

    Nope, it seems everything ok.

    Do you mean there is a bug in that Qt function?


    I've tried to inherit but I got some errors, I'll try to solve them and I'll let you know.

    Quote Originally Posted by ChrisW67 View Post
    I am with andy_skoa. Simple solution for a simple problem rather than trying to make a complex and awkward solution work.

    Another option would be to make the QMainWindow central widget a QStackedWidget with the login UI on one page and the logged in UI on the other... Then just flip between them.
    Hi, yes, maybe you're right but now, I am just interested to know why it doesn't work more than how to do it in another way.

    Thank you anyway, any point of view is welcomed

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Undo the this->setupId(this)

    Quote Originally Posted by ChrisW67 View Post
    I am with andy_skoa. Simple solution for a simple problem rather than trying to make a complex and awkward solution work.
    Indeed. Recreating widget content is almost never a good solution. The only use case where this is needed is when element existence depends on runtime value, e.g. generating n lines of an input form for n entries.

    Content specified by UI file is usually static and only created once.

    Cheers,
    _

  12. #12

    Default Re: Undo the this->setupId(this)

    Ok, I agree. Maybe mine is not the better solution.

    In fact, maybe I'll change the design anyway.... but I still would like to know why it doesn't work

Similar Threads

  1. qt undo/redo
    By giugio in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2012, 16:31
  2. Syncing QTextDocument's undo stack with custom undo stack
    By Dini Selimović in forum Newbie
    Replies: 0
    Last Post: 24th June 2012, 13:11
  3. undo/redo example has refactored
    By n_vova in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2012, 10:04
  4. QtableWidget UNDO
    By afro_cv in forum Qt Programming
    Replies: 15
    Last Post: 5th September 2011, 08:19
  5. buggy undo example
    By Gopala Krishna in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2007, 19:33

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.