LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2011, 03:02 PM   #1
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 689

Rep: Reputation: 106Reputation: 106
QT: popup a dialog on application start


Hiyas, another question, while I was getting back to programming (getting quite nice so far);

Anyway, here is something that is puzzling me and cannot think up a good way around it: I call the constructor and show elements of LoginDialog in the constructor of my QMainWindow, like this:

PHP Code:
MainWindow::MainWindow(QWidget *parent) :
    
QMainWindow(parent),
    
ui(new Ui::MainWindow)
{
    
ui->setupUi(this);

    
LoginDialog *lid = new LoginDialog(this);
    
lid.show();

LoginDialog is a QDialog and it does show up on application start... but...
It is not active! The QMainWindow is the active window, even if I put lid->activateWindow();

So, the question is: how do I pop up this dialog on application start in such a way that it will show the LoginDialog on startup as active window?
 
Old 04-06-2011, 09:47 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
I'm not certain why you are getting the behaviour you have mentioned but:

I'd use exec() rather than show() This will display the dialog as a modal and thus block until the user has closed it. You can then check to see the response of the user (have they successfully logged in?)

Given that this is in the constructor of the MainWindow making the MainWindow the parent of the dialog (this) may be problematic, a dialog parent can be (and defaults to) 0 so I'd just do that. It's modal so you don't need a parent.
 
1 members found this post helpful.
Old 04-07-2011, 02:08 AM   #3
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 689

Original Poster
Rep: Reputation: 106Reputation: 106
Thanks for that suggestion; exec() indeed fixed the behaviour; However, if I do not give it a parent the program will segv; It is logical, as there is some logic in the login window "on_accept()" that sets a few properties in the main window (deactivate the Login option in the menuBar, activate other options. LoginDialog(this) gives the proper behaviour and I put the userid in the MainWindow class as a private: with public functions setUserid(int) and setUsername(QString), allowing access to this data in other windows through int getUserid() and getUsername().

Reminds me that I search for menu options to activate/deactivate like this:

PHP Code:
    QMenuBar *mainmenu;
    
QMenu *listmenu;
    
QList<QAction *> list;

    
mainmenu this->menuBar();
    
listmenu=mainmenu->findChild<QMenu *>("menuFile");
    list=
listmenu->actions();

    for(
int cnt=0;cnt < list.size();cnt++)
    {
        if(list.
at(cnt)->text() == "Login")
        {
            list.
at(cnt)->setEnabled(true);
        }
        else if(list.
at(cnt)->text() == "Logout" 
                
|| list.at(cnt)->text() == "Import"
                
|| list.at(cnt)->text() == "Export" )
        {
            list.
at(cnt)->setEnabled(false);
        }
    } 
That's probably not the most effective way, but could not find a convenient way to find QActions in a QMenu in such a way that I am certain which one's which.; This sort of works, but I still have a icky feeling about it. QMenu::findChild<QAction *>("name") did not appear to work...
 
Old 04-07-2011, 02:27 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
When you create the action it will have name for example actionLogin. So just access it directly, probably ui->actioLogin->setEnabled(true);
 
Old 04-07-2011, 03:28 AM   #5
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 689

Original Poster
Rep: Reputation: 106Reputation: 106
Funny, got to try that out, although I think I tried to access it through MainWindow:

PHP Code:
MainWindow *mw = ((MainWindow *)this->parent());
mw->actionLogin->setEnabled(true); 
but that didn't work; I might have to access it through ui, which is indeed more logical; Going to give it a shot :-) Marking this thread as solved, as the issue is actually solved... I'll come with more questions later, no doubt :-)
 
  


Reply

Tags
qt c++


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ubuntu 8.10: launching tweetdeck from run application dialog deostroll Linux - Desktop 0 01-17-2010 03:19 AM
how to send a popup dialog to all users? KFC123 Linux - Newbie 1 07-02-2009 12:48 AM
Converting a shell script with dialog boxes into a GNOME application kushalkoolwal Programming 4 10-17-2008 06:21 AM
titlebar for file chooser dialog is missing for glade application vishudh Programming 0 07-06-2008 05:08 AM
"Run Application" dialog box NOT running applications trident Linux - Desktop 5 03-12-2008 10:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration