Update form when change in Pushbutton text
hi,
I have one form named fin button i orm1 and this form contain a pushbutton which contain text Login. Once i clicked the login button, i can able to open a login window. Once i login successfully,i need to change the button text to Logout.i have changed that using settext(logout);. But This is getting changed only when i refresh that form1.
Here is ma question, how can i update the form once the button text get changed.??
Could you please help me to sort out this issue.?
Thanks in advance..
Re: Update form when change in Pushbutton text
QAbstractButton::setText() is the correct way to change the text of the button.
What do you mean by, "But This is getting changed only when i refresh that form1" ? Perhaps you can post a small compilable program that demonstrates the problem.
Re: Update form when change in Pushbutton text
Thanks for your reply
This is the login click button handler in form 1
Code:
void MainPage::LoginClickHandler()
{
LoginWindow *f2 = new LoginWindow;
// this->hide();
f2->show();
f2->activateWindow(); // or form2->setActiveWindow() in Qt3
f2->raise();
}
and in login form ,
Code:
void LoginWindow::LoginClicked()
{
StoredPassword.sprintf("%s",LoginPassword);
Password =ui->QLinePassword->text();
//validate password
int x
= QString::compare(Password, StoredPassword
);
// x == 0 if correct if(x==0)
{
ui->QLabelIncorrectPass->setText("Login Successful");
LoginFlag =1;
this->close();
}
else
{
ui->QLabelIncorrectPass->setText("Incorrect Password");
}
}
And i have added the text from login to logout in the constructor of mainpage.
Once the Login window get opened,the mainpage also should be open and once login is successful,the result should be updated in the mainpage as well
Is there any other way to do it.
Thanks.
Re: Update form when change in Pushbutton text
use simple signal slot system.. when use "click" the button, first change the form then set the button text
Re: Update form when change in Pushbutton text
Or use a modal login dialog.
Re: Update form when change in Pushbutton text
Thanks for your reply...
will Update form 1 from form 2 will solve this issue?
i am new to QT, so could you please clarify me with a piece of code.
Thanks
vinithr
Re: Update form when change in Pushbutton text
Instead of using more than one forms you can use stacked widget where you easily moved to next widget once login is valid.
So you might not have problems with forms. Simple by changing the widget index you move to next widget.
Re: Update form when change in Pushbutton text
Hi,
Thanks for your reply.
In the case of signals and slots,i tried to add that button text after loading the page. In this case button text also changing once the login appears. And if i am clicking the cancel button in login form,the button text should be login only. This will not happen in the suggestion.
My requirement is like, change the text of push button from other form or any other mechanism available in QT in the same window.
Thanks in advance.
vinithr
Re: Update form when change in Pushbutton text
Use a modal dialog and change the push button on the main form from the main form. It's really quite straightforward and I am feeling generous:
Code:
#include <QtGui>
#include <QDebug>
class LoginDialog
: public QDialog { Q_OBJECT
public:
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
layout->addWidget(pwEdit);
layout->addWidget(buttonBox);
setLayout(layout);
}
public slots:
void accept() {
if (pwEdit
->text
() == QString("xyzzy")) }
private:
};
Q_OBJECT
public:
connect(button, SIGNAL(clicked()), SLOT(buttonClicked()));
setCentralWidget(button);
}
public slots:
void buttonClicked() {
if (button->text() == "Login") {
LoginDialog dialog;
int result = dialog.exec();
// do login stuff
button->setText("Logout");
}
}
else {
// do logout stuff
button->setText("Login");
}
}
private:
};
int main(int argc, char *argv[])
{
MainWindow m;
m.show();
return app.exec();
}
#include "main.moc"
Re: Update form when change in Pushbutton text
Thanks for your help with source. I will check this and let you know the result.
Thanks Vinithr
Added after 27 minutes:
hi. Thanks for your reply.
Now it is working as i expected.
Thanks lot for your help
regards
vinithr
Re: Update form when change in Pushbutton text
It is the solution I suggested you adopt back in April. Please take the time to understand how it works.
Re: Update form when change in Pushbutton text
Thanks .. i understood the working of thsis application..
Thanks
Vinithr