Text from file not showing

+1 Ernie Peters · January 23, 2015
Just followed the complete set of 14 videos and they were great. However, I can't get my text showing on the main window in the last tutorial. I don't know what it is but I followed every step that Bucky showed. I had to manually copy the txt file to the resource location as it did not ask me to do it like in the video. Could this be pointing to my problem perhaps? Any help greatly appreciated.

Post a Reply


Oldest  Newest  Rating
+1 Jake Scaife · January 23, 2015
If you post your code (remember the code tags!) we will be more than happy to help you out :D 

Without seeing your code it's kinda hard to tell what has gone wrong!
0 Ernie Peters · January 24, 2015
#include <QTCore/QFile>
#include <QTCore/QTextStream>
#include "findcrap.h"
#include "ui_findcrap.h"

FindCrap::FindCrap(QWidget *parent) : QWidget(parent),
ui(new Ui::FindCrap)

delete ui;

void FindCrap::on_goButton_clicked()
QString word = ui->lineEdit->text();
ui->textEdit->find(word, QTextDocument::FindWholeWords);

void FindCrap::getTextFile()
QFile myFile(":/crapAboutBucky.txt");
QTextStream textStream (&myFile);
QString line = textStream.readAll();
QTextCursor textCursor = ui->textEdit->textCursor();
textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);

and in the Resources folder I got crapAboutBucky.txt (just like the tut)

when I changed the prefix to '/' in QT and then clicked 'Add File'. I browsed to my desktop where I kept the .txt file and clicked open. However, it did not ask me to copy the file to the resource folder (project save location) so I had to manually copy it into there. I don't know if this has anything to do with it but the .txt file does show up in the Resources folder in QT as per the tutorial
0 Ernie Peters · January 24, 2015
I just figured out what my mistake was. I forgot to call the getTextFile() ; function right after

I rebuild and ran it and the results are fantastic.

Thanks for your respons though Jake. I'll remember to include the code for my next posts. It was my first post on here.

P.S. By 'code tags', do you mean just to include the code with the post or is there a special way to share code on here?
+1 Jake Scaife · January 25, 2015
You can use code tags just by hitting the little code icon.. As you did in the above post ;)

Glad you got it working! If you need any more help let us know :D
  • 1



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator