Results 1 to 5 of 5

Thread: help..!!

  1. #1
    Join Date
    Jun 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default help..!!

    hi..
    i wrote a code which would display a dialog box initially and after you press the ok button the main window gets displayed... so in order to link the button clicked signal with show() of the main window,i created a custom signal btnclicked() and defined it as follows:

    Qt Code:
    1. void dialog::btnclicked()
    2. {
    3. w1.show();
    4. }
    To copy to clipboard, switch view to plain text mode 

    and then i connected the clicked() signal of the button with my custom signal

    Qt Code:
    1. connect(ok,SIGNAL(clicked()),this,SIGNAL(btnclicked()));
    To copy to clipboard, switch view to plain text mode 

    now i am just getting the dialog box and after i click the ok button nothing gets displayed...
    Now am i overlooking something...??

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    14
    Thanked 41 Times in 35 Posts

    Default Re: help..!!

    btnclicked() in this case would be a SLOT. That's likely your problem.

  3. #3
    Join Date
    Jun 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help..!!

    whoops...!! my mistake.... but even i change it to slot,my problem remains the same...!! plz help..!!

  4. #4
    Join Date
    Jan 2006
    Location
    Lincoln, NE USA
    Posts
    177
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3
    Thanked 7 Times in 6 Posts

    Default Re: help..!!

    Below is main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include "homestead.h"
    3. #include "dlglogin.h"
    4.  
    5. #define DBDRIVER "QPSQL"
    6. #define DBHOST "localhost"
    7. #define DBNAME "hap2008"
    8.  
    9. int main( int argc, char * argv[] ) {
    10. QString strRejected = "";
    11. QApplication app(argc, argv);
    12. app.setQuitOnLastWindowClosed(false); // may not be needed any more
    13. dlgLogin dlg;
    14. if( dlg.exec() == QDialog::Accepted ){
    15. QSqlDatabase hapdb = QSqlDatabase::addDatabase(DBDRIVER);
    16. hapdb.setHostName(DBHOST);
    17. hapdb.setDatabaseName(DBNAME);
    18. hapdb.setUserName(dlg.dui.leUserName->text());
    19. hapdb.setPassword(dlg.dui.leUserPassword->text());
    20. if ( hapdb.open() ) {
    21. homestead ht;
    22. ht.RevID = dlg.dui.leUserName->text();
    23. ht.show();
    24. app.setQuitOnLastWindowClosed(true); // may not be needed any more
    25. return app.exec();
    26. } else {
    27. strRejected = QString("Reason: %1").arg(hapdb.lastError().text()).toLatin1();
    28. QMessageBox::information(0,"Login Rejected!",strRejected,
    29. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
    30. return 1;
    31. }
    32. } else {
    33. strRejected = QString("User Canceled the login!").toLatin1();
    34. QMessageBox::information(0,"Login Canceled!",strRejected,
    35. QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
    36. return 2;
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 



    Below is file dlglogin.h:
    Qt Code:
    1. #ifndef DLGLOGIN_H
    2. #define DLGLOGIN_H
    3. #include "ui_dlglogin.h"
    4.  
    5. class dlgLogin : public QDialog
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. Ui::dlgLoginUi dui;
    11. dlgLogin()
    12. {
    13. // Only ID and password required in UI. No cpp file needed.
    14. dui.setupUi(this);
    15. dui.leUserName->setText("");
    16. dui.leUserPassword->setText("");
    17. dui.leUserName->setFocus();
    18. dui.leUserName->selectAll();
    19. }
    20. };
    21.  
    22. #endif
    To copy to clipboard, switch view to plain text mode 

    In dlglogin.ui form file the form object is called "dlgLoginUi" and contains the name and password as textboxes. The cancel button is connected to the reject() function and the OK button is connected to the accept() function.

    There is more explainations in the forum tutorial
    http://wiki.qtcentre.org/index.php?title=Programming_in_Qt4_and_C%2B%2B


  5. #5
    Join Date
    Jun 2008
    Posts
    26
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: help..!!

    now I am not intending to put a login dialog in my code... what i want exactly to do is i want to provide two options in the dialog say two radio buttons...selecting one displays a widget with a particular layout and selecting the other displays a the same widget with a completely different layout,say a with a few more things included for example - a table etc....

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.