私は現在アクティブなウィンドウのすべてのボタン子ウィジェットを取得しようとしています。ボタンはQDialogButtonBoxによって作成されました。私は各ボタンの役割を取得しようとしているので、どのボタンがOK、CANCEL、またはSAVEボタンであるかを識別できます。しかし、私は次のコードでエラーを取得しています:QDialogButtonBoxによって作成されたQPushButtonの役割を取得する方法は?
QWidget *pWin = QApplication::activeWindow();
QList<QPushButton *> allPButtons = pWin->findChildren<QPushButton *>();
QListIterator<QPushButton*> i(allPButtons);
while(i.hasNext())
{
QDialogButtonBox *pButtonRole = new QDialogButtonBox();
QDialogButtonBox::ButtonRole role = pButtonRole->buttonRole(i.next());
qDebug() << "buttonRole: " << role << endl ;
//the value of role here is -1, which means it's an invalid role...
}
ボタンの役割を取得するとき、私は負の値を取得しています:(
誰かがコードと間違って何を教えてもらえます
どちらのjkerianが言っどのように行うか、標準のボタンを使用すると、単純にボタンのいずれかが必要な場合:のQPushButton * OK = buttonBox- >ボタン(QDialogButtonBox :: Ok) –
私はQDialogButtonBoxを試しました。pButtonRole =新しいQDialogButtonBox(); QDialogButtonBox :: ButtonRole role = pButtonRole-> buttonRole(i.next()); qDebug()<< "buttonRole:" << role << endl;私は無効な役割を持っています... -1 ... – Owen