C GUI文本未显示
C++ GUI Text Not Displaying
基本上,我制作了一个简单的程序来搜索文本文件中的某个单词。但是,我的文本文件没有在文本dedit对象中显示,它只是显示为空白。我将文本文件正确地放入资源和所有内容中。我真的很感谢一些投入。
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include "find.h"
#include "ui_find.h"
Find::Find(QWidget *parent) : QWidget(parent), ui(new Ui::Find)
{
ui->setupUi(this); //sets up user interface
getTextFile();
}
Find::~Find()
{
delete ui;
}
void Find::on_goButton_clicked()
{
QString word = ui->lineEdit->text(); //gets text and stores in word
ui->textEdit->find(word, QTextDocument::FindWholeWords);
}
void Find::getTextFile()
{
QFile myFile(":/textfile.txt"); //what file
myFile.open(QIODevice::ReadOnly); //opens file
QTextStream textStream(&myFile); //convert to stream
QString line = textStream.readAll(); //store into variable
myFile.close(); //close file
ui->textEdit->setPlainText(line); //display text
QTextCursor textCursor = ui->textEdit->textCursor(); //moves cursor into position
textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); //moves cursor into position
}
应用程序输出还具有红色字母Qiodevice :: read:设备不打开
QT创建者的清洁重建被打破。只需永久删除QMAKE保留特定项目的套件特定文件夹即可。
尝试再次构建。RCC将被特定于.qrc文件的特定调用,这些文件被旧的makefile文件跳过,因为Qmake必须立即提供新的makefile文件。
我有QT 5.4,并且我的代码在使用MSVC2010 OpenGL作为编译器时给出了相同的错误。我手动添加了mingw 32bit将其用作编译器,并且可以使用。P.S.我尚未为QT 5.4安装MSVC2013,有时与MSVC2010 OpenGL一起使用而无需错误,但在这种情况下也没有。
确保您在项目中添加了QRC文件。如果将QRC文件用作外部源,则应通过call qresource :: registerresource("文件路径")在主函数中进行注册。
我只是以相同的错误/症状解决了此问题。问题是我没有用于构建套件的工作编译器。我最终必须手动选择我的Microsoft Visual C 编译器11.0(x86)。我想它无法自动检测它。对于开始QT5的新Windows用户,这似乎是一条常见的错误消息。
相关文章:
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 动态填充的组合框不显示文本,列表未定义
- QTreeWidgetItem 突出显示文本问题
- 如何通过单击按钮在QTextEdit中显示文本?
- 在C Windows程序中显示文本文件内容
- findChild 从不显示文本浏览器
- C 在同一行中左右显示文本
- 使用 C++ 中的向量在新行上显示文本文件中的列
- 如何使用 Opengl 库显示文本文件中的 3D 点
- Qt. 方法显示文本() 如果我在 QStyledItemDelegate 中定义了 paint() 方法不起作用
- 如何在C 中的OpenGL中通过矩形显示文本
- 如何使用键盘输入和sf ::文本在SFML中添加一种文本框以显示文本字符串
- QMessageBox:无法在框中显示文本(使用 c++)
- 延迟窗口在 MFC 上显示文本
- Visual Studio代码集成的终端未显示文本
- SFML-不显示文本
- qprogressdialog未显示文本标签
- C++程序无法正确显示文本文件中的内容
- 如何在不显示文本的情况下分配Win32编辑控件的窗口名称
- SDL2 OpenGL SDL2_TTF:显示文本