Qt QDialog问题:QLineEdit将不接受输入
Qt QDialog Issue : QLineEdit Will Not Take Input
我有这个基本的Qt程序,它来自于《c++ GUI Programming with Qt》一书。然而,当我按照说明(因为这本书是为Qt 4.4编写的),我的QLineEdit将不显示键盘输入的文本。
源代码如下(我没有包括moc_*.cpp文件)。对于那些不喜欢通过复制和粘贴来重新组装代码的人来说,整个项目可以从我的subversion PlayGround下载:
http # 58;//matthewh.me/Qt4Devel/gotocell//操场/分支用户=客人密码=客人
#include <QApplication>
#include <QDialog>
#include <iostream>
#include "gotocelldialog.h"
int main( int argc, char *argv[ ] )
{
QApplication app( argc, argv );
GoToCellDialog *dialog = new GoToCellDialog;
dialog->show( );
dialog->activateWindow( );
dialog->lineEdit->activateWindow( );
return app.exec( );
}
#include <QtGui>
#include <iostream>
#include "gotocelldialog.h"
GoToCellDialog::GoToCellDialog( QWidget *parent )
: QDialog( parent ) /* Call Parents Constructor */
{
setupUi( this );
lineEdit->setEchoMode( QLineEdit::Normal );
QRegExp regExp( "[A-Z][a-z][1-9][0-9]{0,2}" );
lineEdit->setValidator( new QRegExpValidator( regExp, this ) );
//connect( okButton, SIGNAL( clicked( ) ), this, SLOT( accept( ) ) );
//connect( cancelButton, SIGNAL( clicked( ) ), this, SLOT( reject( ) ) );
}
void GoToCellDialog::on_lineEdit_textChanged( )
{
//okButton->setEnabled( lineEdit->hasAcceptableInput( ) );
}
#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
#include <QDialog>
#include "ui_gotocelldialog.h"
/* Adapter Class */
class GoToCellDialog : public QDialog, public Ui::GoToCellDialog
{
Q_OBJECT
public:
GoToCellDialog( QWidget *parent = 0 );
private slots:
void on_lineEdit_textChanged( );
};
#endif
/********************************************************************************
** Form generated from reading UI file 'gotocelldialog.ui'
**
** Created: Sat Aug 20 23:05:28 2011
** by: Qt User Interface Compiler version 4.7.3
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_GOTOCELLDIALOG_H
#define UI_GOTOCELLDIALOG_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
QT_BEGIN_NAMESPACE
class Ui_GoToCellDialog
{
public:
QLineEdit *lineEdit;
void setupUi(QDialog *GoToCellDialog)
{
if (GoToCellDialog->objectName().isEmpty())
GoToCellDialog->setObjectName(QString::fromUtf8("GoToCellDialog"));
GoToCellDialog->resize(286, 110);
lineEdit = new QLineEdit(GoToCellDialog);
lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
lineEdit->setGeometry(QRect(92, 23, 165, 24));
retranslateUi(GoToCellDialog);
QMetaObject::connectSlotsByName(GoToCellDialog);
} // setupUi
void retranslateUi(QDialog *GoToCellDialog)
{
GoToCellDialog->setWindowTitle(QApplication::translate("GoToCellDialog", "Go to Cell", 0, QApplication::UnicodeUTF8));
lineEdit->setPlaceholderText(QString());
} // retranslateUi
};
namespace Ui {
class GoToCellDialog: public Ui_GoToCellDialog {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_GOTOCELLDIALOG_H
我最近也遇到过类似的问题。
我是这样解决这个问题的:
mainwindow->centralWidget()->releaseKeyboard();
我解决了这个问题,我没有仔细阅读,我应该创建一个小部件而不是一个对话框。仍然好奇为什么对话框不接受输入。我认为这与QDialogBox不是顶级小部件的事实有关?
我也遇到过同样的情况。
当我使用this->setWindowFlags(Qt::Popup| Qt::FramelessWindowHint);
时,输入不工作。如果这一行被删除,输入工作正常,但是我不能隐藏小部件。
相关文章:
- 为什么线程不接受此输入?
- B不接受8作为输入的是什么?C++
- C++数组输入不接受一定数量的整数
- C++ 我的开关格式中的循环不允许我显示菜单选项或接受输入?
- 斯堪夫不接受输入
- C++字符数组不接受超过 4 个字符的输入
- CIN不接受C++中带有空格的输入?
- std::cin不接受输入
- 为什么我的代码在要求打印长度和宽度的值后不接受多个输入?
- 在此代码中,它不接受 i=0 的输入.它直接用于 i=1
- 有没有一种方法可以接受数字数组而不接受垃圾值的输入
- 为什么在接受输入后循环退出时不会这样做
- 扫描线C++不接受输入的功能
- 为什么getline不接受输入
- gets() 不接受输入
- cin 不接受输入作为输入
- 命令提示符关闭而不接受输入
- while循环中的迭代在不接受输入的情况下运行和结束
- Qt QDialog问题:QLineEdit将不接受输入
- cin不接受输入,程序立即关闭