Qt で簡単なログインフォームを作成しようとしています。ユーザー名とパスワードが正しければ、別のフォームを開くはずです。しかし、その動作は本当に奇妙で、私のコードは次のとおりです。
login::login(QWidget *parent) :
QDialog(parent)
{
QPushButton * login_button = new QPushButton;
QPushButton * exit = new QPushButton;
login_button->setText("LOGIN");
exit->setText("EXIT");
QLineEdit * username = new QLineEdit;
QLineEdit * password = new QLineEdit;
QVBoxLayout * login_layout = new QVBoxLayout ;
QHBoxLayout * button_layout = new QHBoxLayout ;
username->setText("Enter Username ...");
password->setText("Enter Password ... ");
exit->connect(exit,SIGNAL(pressed()),this , SLOT(close()));
login_layout->addWidget(username);
login_layout->addWidget(password);
button_layout->addWidget(login_button);
button_layout->addWidget(exit);
login_layout->addLayout(button_layout);
this->setLayout(login_layout);
this->connect(login_button,SIGNAL(clicked()),this,SLOT(finduser()));
}
void login::finduser()
{
if (username->text().compare("admin")) // <---- problem !!
emit showmanage() ;
return;
}
finduser は、私のダイアログ クラスの SLOT です。フォームを開く「showmanage」シグナルを発行します。実際の問題は if 文にあります。理由はわかりませんが、実行するとウィンドウがクラッシュします。これも機能しません:
void login::finduser()
{
if (username->text()=="admin") // <---- problem !!
emit showmanage() ;
return;
}
何が間違っているのかわかりません。デバッグ メッセージも表示されます。オペレーティング システムから信号を受信したため、下位が停止しました。信号名: sigsegv 信号の意味: セグメンテーション違反