PDA

View Full Version : Whre is the mistake?



unix7777
18th March 2010, 10:43
I try to load (read) text file in the textEdit doing the following:

QString myFile="data/bgen.txt";
QFile file(myFile);
QTextStream stream( &myFile );
if (file.open(QFile::ReadOnly | QFile::Text))
ui->textEdit->setPlainText(file.readAll());

When i click the Button nothing happens.

i add the link of the file in the resources

high_flyer
18th March 2010, 10:47
By default, resources are accessible in the application under the same name as they have in the source tree, with a :/ prefix. For example, the path :/images/cut.png would give access to the cut.png file, whose location in the application's source tree is images/cut.png. This can be changed using the file tag's alias attribute:

Also, make sure your signal/slot connection is valid.

unix7777
18th March 2010, 11:11
the slot is done like this:
connect(ui->pushButton_search, SIGNAL(clicked()), this, SLOT(select_dictionary()));

Lykurg
18th March 2010, 11:52
Check if your path to the file is correct. To verify that, use an absolute path.

unix7777
18th March 2010, 19:09
i did it but it keeps to not work when i do click
what is the role of the prefix in resources , it must be set the same as the path or not?

ChrisW67
18th March 2010, 23:17
What is stream declared for? You are not using it.

You are calling QFile::readAll() which returns a QByteArray that you are implicitly converting to Unicode in a QString when you set the text edit. There are possibly a couple of ways this might give you something other than what you expect: e.g. if the input file
contains 0x0 (NUL) bytes or is already UTF8 encoded.

Have you tried single-stepping this in your debugger?

wysota
18th March 2010, 23:30
I think the main question should be whether you are trying to read data from a file in your filesystem or from a file residing in Qt resource system embedded into the application binary. The second question should be whether your slot is actually called. The latter can be verified by placing a debug statement inside the slot and seeing if it gets printed to the console when you click the button.