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?
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?
Hi,
You can use signal and slot connection:
YourNewWidget *widget=new YourNewWidget();
connect(ui->HisoitalityBtn,SIGNAL(clicked()),widget,SLOT(showMaximized()));
Hopefully that will help![]()
I tried this. But no use. I am writing my code below. Please check it and let me know my mistake.
Here, HospRefineSearch is the name of my second form(which I want to activate)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(); }
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 ?
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
Also, please tell me I used below codeCode:#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; };
rather thanCode:void AppUi::on_btnHospitality_clicked() { HospRefineSearch *widget=new HospRefineSearch(); widget->showMaximized(); }
Is it correct or not?Code:connect(ui->btnHospitality,SIGNAL(clicked()),widget,SLOT(showMaximized()));
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())); }
I have already tried this. But this also didn't worked for me .
ok please try to define you object on appui.h as a member like this:
and in cpp file:Code:HospRefineSearch *widget;
I don't know just give it a tryCode:void AppUi::on_btnHospitality_clicked() { widget=new HospRefineSearch(); widget->showMaximized(); }![]()
Tried this. Still the same problem.ok please try to define you object on appui.h as a member like this:
Anyways, Thanks a lot for your suggestions.I don't know just give it a try
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
But one should always capture and test the return code from connect() as follows;Code:connect(ui->btnHospitality,SIGNAL(clicked()),widget,SLOT(on_btnHospitality_clicked()));
Code:bool ok = connect(...); Q_ASSERT(ok); Q_UNUSED(ok);
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".
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:in your .h file.Code:public slots: void on_btnXyz(); .....
Please read the excellent documentation section on signals & slots.