Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could subclass QDialog and use it as a message box</p> <p>searchdialog.h:</p> <pre><code>#ifndef SEARCHDIALOG_H #define SEARCHDIALOG_H #include &lt;QDialog&gt; #include &lt;QLineEdit&gt; class SearchDialog : public QDialog { Q_OBJECT public: explicit SearchDialog(QWidget *parent = 0); QString searchString() const; private: QLineEdit *m_lineEdit; }; #endif // SEARCHDIALOG_H </code></pre> <p>searchdialog.cpp</p> <pre><code>#include "searchdialog.h" #include &lt;QVBoxLayout&gt; #include &lt;QPushButton&gt; #include &lt;QDialogButtonBox&gt; SearchDialog::SearchDialog(QWidget *parent) : QDialog(parent) { m_lineEdit = new QLineEdit(this); QPushButton *searchButton = new QPushButton(tr("Search")); searchButton-&gt;setDefault(true); QPushButton *cancelButton = new QPushButton(tr("Cancel")); QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal); buttonBox-&gt;addButton(searchButton, QDialogButtonBox::AcceptRole); buttonBox-&gt;addButton(cancelButton, QDialogButtonBox::RejectRole); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QVBoxLayout *lt = new QVBoxLayout; lt-&gt;addWidget(m_lineEdit); lt-&gt;addWidget(buttonBox); setLayout(lt); } QString SearchDialog::searchString() const { return m_lineEdit-&gt;text(); } </code></pre> <p>main.cpp</p> <pre><code>#include &lt;QtGui/QApplication&gt; #include &lt;QtGui/QMessageBox&gt; #include &lt;QLabel&gt; #include "searchdialog.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QLabel lbl; SearchDialog *dialog = new SearchDialog(&amp;lbl); lbl.show(); QString searchString; if (dialog-&gt;exec()) { searchString = dialog-&gt;searchString(); lbl.setText(searchString); } return a.exec(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload