2014-02-25 222 views
0

Goodday,QT Creator QlineEdit

我對Qt很新,我對QlineEdit有問題。當我運行程序時,它向我展示了QSpinEdit而不是QLineEdit框。我需要在QLineEdit的輸入3個值和計算的標誌,這將在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; 
} 

回答

1

其因對話框,你看,實現如下:

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())); 
    } 
... 
}; 

所以,如果你需要QLineEdit-基本對話框,你必須自己實現它。

+0

你在哪裏看到他的代碼中有'QInputDialogSpinBox'? QInputDialog :: getDouble實現中的 –

+0

。 – gooddocteur

+0

我迷路了。我沒有看到我的代碼中的QInputDialogSpinBox。你能否進一步解釋一下。謝謝 – user1291092