无法编辑QlineEdit
unable to edit QlineEdit
我正在使用一本名为《c++编程gui与qt 4第二版》的书中的一个例子,并遇到了以下问题;我不能编辑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}应该是逗号,而不是连字符(-)
相关文章:
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- Qt和C++:将QLineEdit添加到QTabWidget中
- 如何从QToolBox中动态创建的QLineEdit中获取文本
- 编辑文件中的文本
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- SetDlgItemInt 不会更改嵌入资源的编辑框
- 我无法在Visual Studio代码中使用CIN输入答案,它说输入您的年龄,但它说只读文本编辑器如何解决这个问题?
- C++,Qt:仅在双击后编辑qtablewidget项目
- 编辑字符串以包含括号 c++ 之间的变量
- Arduino函数无法编辑数组
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- "未定义对'WinMain@16'的引用"gcc 编辑器中的错误
- C++MFC编辑框处理双击
- 是否可以使用指针访问变量以避免直接编辑变量?
- 在QLineEdit中显示和编辑转义字符
- 如何使QLineEdit编辑在文本来自QPushButton时启用
- 通过按 Enter 完成编辑时更改或清除 QLineEdit 上的焦点,并在 Qt 中仅发送一个信号
- QLineEdit with QValidator:不管输入的有效性如何,对编辑完成做出反应
- 无法编辑QlineEdit
- 如何使QLineEdit在Windows中不可编辑