C GUI文本未显示

C++ GUI Text Not Displaying

本文关键字:显示 文本 GUI      更新时间:2023-10-16

基本上,我制作了一个简单的程序来搜索文本文件中的某个单词。但是,我的文本文件没有在文本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用户,这似乎是一条常见的错误消息。