Question

I am very new to Qt and I have a problem with the QlineEdit. When I run the program it shows me the QSpinEdit not the QLineEdit box. I need to enter 3 values in the QlineEdit and calculate a mark which will display in QMessageBox

#include <QtGui>


int main (int argc, char* argv[]) {
    QApplication app(argc, argv);

    bool ok;
    double answer, mark;


    do {

        mark = QInputDialog::getDouble(0, "MarkCalc", "Enter the assignment marks:", QLineEdit::Normal, ok);

        double a1 = mark/100 * 20/100;
        double a2 = mark/100 * 50/100;
        double a3 = mark/100 * 30/100;
        double ym = (a1 +a2 +a3) *20;
        double em = 80 * ym;
        QString rep = QString("Final Mark: %1").arg(em);
        answer = QMessageBox::question(0, "Final Marks", rep,QMessageBox::Yes | QMessageBox::No);
       } while (answer == QMessageBox::Yes);
    return 0;
}
Was it helpful?

Solution

Its because the implementation of dialog which you see is:

class QInputDialogSpinBox : public QSpinBox {
Q_OBJECT
public:
  QInputDialogSpinBox(QWidget *parent) : QSpinBox(parent) {
    connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged()));
    connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged()));
  }
...
};

So, if you need QLineEdit-base dialog, you must implement it by yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top