簡體   English   中英

無法編輯QlineEdit

[英]unable to edit QlineEdit

我從一本名為“用Qt 4第二版對gui進行編程的書”中的示例中,遇到了以下問題; 我無法編輯QlineEdit。 我很確定是QRegExp引起了問題,因為當我注釋掉它時,我突然能夠在QlineEdit對話框中輸入輸入。

這是下面的代碼:

cells.h:

    #ifndef CELLS
    #define CELLS

    #include <QDialog>
    #include "ui_cells.h"

    class cells: public QDialog, public Ui::cells
    {
        Q_OBJECT

    public:
        cells(QWidget *parent = 0);

    private slots:
        void on_lineEdit_textChanged();
    };


    #endif // CELLS

cells.cpp:

    #include <QtWidgets>
    #include "cells.h"

    cells::cells(QWidget *parent) : QDialog(parent)
    {
        setupUi(this);

        QRegExp regExp("[A-Za-a] [1-9] [0-9] {0-2}");
        lineEdit->setValidator(new QRegExpValidator(regExp, this));

        connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
        connect(Cancel, SIGNAL(clicked()), this, SLOT(reject()));
    }

    void cells::on_lineEdit_textChanged()
    {
        okButton->setEnabled(lineEdit->hasAcceptableInput());
    }

最后是main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    #include "cells.h"

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        cells *dialog = new cells;
        dialog->show();

        return a.exec();
    }

抱歉,發現了問題所在:

在regExp的聲明中應為:

    QRegExp regExp = ("[A-Za-z] [1-9] [0-9] {0,2}")

應該在{0,2}處使用逗號而不是連字符(-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM