Where does QTemporaryFile output the file?

1,549 views
Skip to first unread message

Nakasya

unread,
Feb 27, 2011, 9:53:29 PM2/27/11
to android-qt
Hi,

I think that QTemporaryFile always fails.
Where does QTemporaryFile output the file? /sdcard?

thanks.

BogDan Vatra

unread,
Mar 1, 2011, 1:10:46 AM3/1/11
to andro...@googlegroups.com
Hi Nakasya,

Depends on how you use QTemporaryFile:

The following code should create a temporary file into your home phone
directory:

QTemporaryFile tempFile;
qDebug()<<tempFile.open();
qDebug()<<tempFile.fileName();

It should create
"/data/data/your.package.name/files/qt_temp.some_randome_chars" file
for you.


Also you can specify where to create the temporary file:

QTemporaryFile file(QDir::tempPath()+"/tempFile");
qDebug()<<file.open();
qDebug()<<file.fileName();

It should create
"/data/data/your.package.name/files/tempFile.some_randome_chars" file
for you.

If you want to create it to sdcard, replace QDir::tempPath() with
"/sdcard" and make sure your application has necessary permissions to
write on sdcard.

Cheers,
BogDan.


2011/2/28 Nakasya <nakas...@gmail.com>:

Nakasya

unread,
Mar 2, 2011, 1:50:33 AM3/2/11
to android-qt
Hi, BogDan.

Thank you very much for the answer in spite of a busy schedule.

On 3月1日, 午後3:10, BogDan Vatra <taipanroma...@gmail.com> wrote:
> Depends on how you use QTemporaryFile:
>
> The following code should create a temporary file into your home phone
> directory:
>
> QTemporaryFile tempFile;
> qDebug()<<tempFile.open();
> qDebug()<<tempFile.fileName();


I am using repos at cb4995eda7f3c389417ae23c455 which branch is
android-stable.

"/tmp/qt_temp.some_randome_chars" was made though QTempraryFile did
not make "/data/data/your.package.name/files/
qt_temp.some_randome_chars".
It fails as a result.

I try to change codes in Qt.
I change code in src/corelib/io/gfsfileengine_unix.cpp
- temp = QLatin1String("/tmp/");
+ temp = QLatin1String("/sdcard/AppData/tmp/");

It can make file, after making "/sdcard/AppData/".
Why QTempraryFile try to make temporay file in "/tmp"?

Thank you.
Nakasya

BogDan Vatra

unread,
Mar 2, 2011, 3:02:00 AM3/2/11
to andro...@googlegroups.com
Hi Nakasya,

2011/3/2 Nakasya <nakas...@gmail.com>:

It will try to make temporary files to "/tmp" ONLY if you don't have
TMPDIR environment variable set. That variable is set here
http://qt.gitorious.org/~taipan/qt/android-lighthouse/blobs/android-stable/src/android/java/src/eu/licentia/necessitas/industrius/QtActivity.java#line124
and passed toC++ part which will set it check
http://qt.gitorious.org/~taipan/qt/android-lighthouse/blobs/android-stable/src/android/cpp/qtmain_android.cpp#line78
so, this can happen ONLY if you don't use java files which are shipped
with Necessitas SDK.

> Thank you.
> Nakasya

Cheers,
BogDan.

Reply all
Reply to author
Forward
0 new messages