[Qt-creator] To Open a File and Read It.
alan.westbrook at nokia.com
alan.westbrook at nokia.com
Mon Feb 2 11:55:34 CET 2009
The problem you are encountering is that the GUI uses your home directory as the working dir when you double click and not the application dir.
You want to prepend QApplication::applicationDirPath() to the filename in order to open it from a place relative to the executable.
Alan
-----Original Message-----
From: qt-creator-bounces at trolltech.com [mailto:qt-creator-bounces at trolltech.com] On Behalf Of ext Sarah Hollings
Sent: Monday, February 02, 2009 9:24 AM
To: qt-creator at trolltech.com
Subject: Re: [Qt-creator] To Open a File and Read It.
Hmm.
QFileInfo fi(file);
qDebug() << fi.absoluteFilePath() << "is readable" << fi.isReadable();
If that does not reveal anything useful - desperate hack:
go to the projects tab, run setting, create a custom executable /usr/bin/strace and give the ./<name> of your binary as the argument.
If the output is too big, add -o myapp.out -ff as arguments before the binary name, and grep the outputs for the file name.
On Mon, Feb 2, 2009 at 8:09 PM, Keiver Hdez Fdez <khfernandez at estudiantes.uci.cu> wrote:
>
> Already tried all the three advices, the file.error() function return value 0, QFile::NoError.
> The working directory is the right one. I just checked visually on qtcreator and with qDebug().
>
> Still with no solutions, inside qtcreator the application works fine, but by clicking the executable this does not work.
>
> ----- "Sarah Hollings" <sarah.hollings at gmail.com> wrote:
>
> | Assuming you're running qtcreator and the terminal as the same user,
> | things to try:
> |
> | * Check the run settings on the project tab to see what the working
> | directory is.
> | * Use file.error() to see what the error condition is (look up the
> | value of the enum here:
> | http://doc.trolltech.com/4.4/qfile.html#FileError-enum)
> | * Add some debug:
> | qDebug() << "Current working dir:" << QDir::currentPath() (You'll
> | need to add #include <QDebug> and <QDir>)
> |
> |
> | On Mon, Feb 2, 2009 at 6:40 PM, Keiver Hdez Fdez
> | <khfernandez at estudiantes.uci.cu> wrote:
> | >
> | > Hi there;
> | >
> | > I'm using Qt Creator in a small application and I need to open a
> | file and read it. The thing is that I have this code:
> | >
> | > QFile file("config/exclude_files.exc");
> | >
> | > if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { ...
> | > }
> | >
> | > If I execute the application by clicking, it does not work and if
> | > I
> | executed in a terminal it works fine.
> | >
> | > Any clues?
> | >
> | > Using:
> | > Qt Creator 0.9.2
> | > Based on Qt 4.5.0
> | >
> | > Built on Jan 27 2009 at 03:49:58
> | > OS: Debian GNU/Linux
> | > _______________________________________________
> | > Qt-creator mailing list
> | > Qt-creator at trolltech.com
> | > http://lists.trolltech.com/mailman/listinfo/qt-creator
> | >
> | _______________________________________________
> | Qt-creator mailing list
> | Qt-creator at trolltech.com
> | http://lists.trolltech.com/mailman/listinfo/qt-creator
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-creator
>
_______________________________________________
Qt-creator mailing list
Qt-creator at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator
More information about the Qt-creator-old
mailing list