×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    How to activate another ui on button click event

    Hi

    In my application I have two ui forms. On the first form, I have a push button "Hospitality". Now I have another form (Widget type) which I want to be shown when I press the "Hospitality" button. How can I achieve this?

  2. #2
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: How to activate another ui on button click event

    Hi,

    You can use signal and slot connection:

    YourNewWidget *widget=new YourNewWidget();
    connect(ui->HisoitalityBtn,SIGNAL(clicked()),widget,SLOT(showMaximized()));

    Hopefully that will help

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: How to activate another ui on button click event

    I tried this. But no use. I am writing my code below. Please check it and let me know my mistake.


    Code:
    AppUi::AppUi(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::AppUi)
    {
        ui->setupUi(this);
    }
    
    AppUi::~AppUi()
    {
        delete ui;
    }
    
    void AppUi::changeEvent(QEvent *e)
    {
        QMainWindow::changeEvent(e);
        switch (e->type()) {
        case QEvent::LanguageChange:
            ui->retranslateUi(this);
            break;
        default:
            break;
        }
    }
    
    void AppUi::on_btnAdvancedSearch_clicked()
    {
    
    }
    
    void AppUi::on_btnHospitality_clicked()
    {
       HospRefineSearch *widget=new HospRefineSearch();
        widget->showMaximized();
      }
    Here, HospRefineSearch is the name of my second form(which I want to activate)

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: How to activate another ui on button click event

    What is the result when you run this code ? you click on the button and its just not working ? are you sure you included your HospRefineSearch .h file ?

  5. #5
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: How to activate another ui on button click event

    On clicking the button, nothing is event, no new form is geeting opened. Yes, I have included HospRefineSearch .h file. Its code is mentioned below

    Code:
    #include <QWidget>
    
    namespace Ui {
        class HospRefineSearch;
    }
    
    class HospRefineSearch : public QWidget {
        Q_OBJECT
    public:
        HospRefineSearch(QWidget *parent = 0);
        HospRefineSearch();
    
    protected:
        void changeEvent(QEvent *e);
    
    private:
        Ui::HospRefineSearch *ui;
    };
    Also, please tell me I used below code

    Code:
    void AppUi::on_btnHospitality_clicked()
    {
       HospRefineSearch *widget=new HospRefineSearch();
        widget->showMaximized();
      }
    rather than
    Code:
    connect(ui->btnHospitality,SIGNAL(clicked()),widget,SLOT(showMaximized()));
    Is it correct or not?

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: How to activate another ui on button click event

    Actually they should work the same as I know....your code seems correct !! but try this:

    in your cpp file

    Code:
    AppUi::AppUi(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::AppUi)
    {
        ui->setupUi(this);
    
        HospRefineSearch *widget=new HospRefineSearch();
        connect(ui->Hospitality,SIGNAL(clicked()),widget,SLOT(showMaximized())); 
    }

  7. #7
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: How to activate another ui on button click event

    I have already tried this. But this also didn't worked for me .

  8. #8
    Registered User
    Join Date
    Oct 2010
    Posts
    94

    Re: How to activate another ui on button click event

    ok please try to define you object on appui.h as a member like this:

    Code:
    HospRefineSearch *widget;
    and in cpp file:

    Code:
    void AppUi::on_btnHospitality_clicked()
    {
       widget=new HospRefineSearch();
        widget->showMaximized();
      }
    I don't know just give it a try

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: How to activate another ui on button click event

    ok please try to define you object on appui.h as a member like this:
    Tried this. Still the same problem.

    I don't know just give it a try
    Anyways, Thanks a lot for your suggestions.

  10. #10
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to activate another ui on button click event

    Basically it should work, but you have a serious problem in that you will immediately "lose" your handle to the HospRefineSearch instance, so you won't be able to reference it (or delete it when done).

    Oh! On second look I see you're missing the connect. You need a connect statement along the lines of
    Code:
    connect(ui->btnHospitality,SIGNAL(clicked()),widget,SLOT(on_btnHospitality_clicked()));
    But one should always capture and test the return code from connect() as follows;
    Code:
    bool ok = connect(...);
    Q_ASSERT(ok);
    Q_UNUSED(ok);

  11. #11
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    Re: How to activate another ui on button click event

    You also have a QMainWindow object, which you have setted centralWidget with first widget. So connecting first button clicked signal to a function that change centralWidget for your QMainWindow.

    Try this mine sample:
    http://www.negusweb.it/wiki/%28Engli...Qt_Mobility%29

    Regards camera, but it's so short that you can see how go between "screen".

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: How to activate another ui on button click event

    Quote Originally Posted by danhicksbyron View Post
    Basically it should work, but you have a serious problem in that you will immediately "lose" your handle to the HospRefineSearch instance, so you won't be able to reference it (or delete it when done).

    Oh! On second look I see you're missing the connect. You need a connect statement along the lines of
    Code:
    connect(ui->btnHospitality,SIGNAL(clicked()),widget,SLOT(on_btnHospitality_clicked()));
    But one should always capture and test the return code from connect() as follows;
    Code:
    bool ok = connect(...);
    Q_ASSERT(ok);
    Q_UNUSED(ok);
    ok, so as per I asked in post #5, both the things are different?

  13. #13
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: How to activate another ui on button click event

    Quote Originally Posted by negus View Post
    You also have a QMainWindow object, which you have setted centralWidget with first widget. So connecting first button clicked signal to a function that change centralWidget for your QMainWindow.

    Try this mine sample:
    http://www.negusweb.it/wiki/%28Engli...Qt_Mobility%29

    Regards camera, but it's so short that you can see how go between "screen".
    Thank you. I will check this example.

  14. #14
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to activate another ui on button click event

    You always need a "connect". In some cases you can simply point it at "showMaximized" or some such, while in other cases you need to point it at your own slot.

    (Note that you need to declare the target of a "connect" to be a "slot". Eg:
    Code:
    public slots:
    	void on_btnXyz();
            .....
    in your .h file.

  15. #15
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: How to activate another ui on button click event

    Please read the excellent documentation section on signals & slots.

Similar Threads

  1. How to use button click event in carbide c++?
    By nokia.vtrack in forum Symbian
    Replies: 5
    Last Post: 2010-12-12, 14:23
  2. Dynamically adding a mouse click event to button movieclip
    By ranco in forum [Archived] Flash Lite on Nokia Devices
    Replies: 7
    Last Post: 2010-01-05, 21:52
  3. Replies: 5
    Last Post: 2008-12-08, 08:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×