QTemporaryFile: file not being created in Qt 5.11/5.12
-
We have some tests implemented which use QTemporaryFile. We've found that some tests fail when upgrading from Qt 5.9.8 to Qt 5.11.3, if
QTemporaryFile#fileName()
doesn't get called after callingQTemporaryFile#open()
. We use Xubuntu 16.04 for development.Basically, this is the simplest test case:
TEST(tempFileTest, test1) { QTemporaryFile temp; ASSERT_TRUE(temp.open()); ASSERT_TRUE(temp.exists()); //Fails here }
TEST(tempFileTest, test2) { QTemporaryFile temp; ASSERT_TRUE(temp.open()); temp.fileName(); ASSERT_TRUE(temp.exists()); //Passes }
-
@Aritz
This is a user forum and it is not monitored for bug reports.You can check on https://bugreports.qt.io/secure/Dashboard.jspa if it is a bug and it has been reported.
If it is not reported yet, you can file a bug report. Please report here the bug number. -
Reported as QTBUG-80157. Thanks
-
I don't see it as bug here - a temporary file may not exist on the disk at all so exists() may return false. As soon as you call fileName() you force Qt to create a file on disk and it exists there.
-
That is disputable.
According to the documentation of bool QTemporaryFile::open(QIODevice::OpenMode flags) it says:
Creates a unique file name for the temporary file, and opens it. You can get the unique name later by calling fileName(). The file is guaranteed to have been created by this function (i.e., it has never existed before).For the open used in the code bool QTemporaryFile::open() it states only:
A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the data in the file. This function will return true upon success and will set the fileName() to the unique filename used.Also there seems to be a change in functionality between versions according to the first post.
-
@koahnig said in QTemporaryFile: file not being created in Qt 5.11:
That is disputable.
Then please discuss this on the LKML, O_TMPFILE, when supported, doesn't create visible directory entry. As soon as you want it to be visible (= calling fileName()) this changes. See also e.g. here: http://man7.org/linux/man-pages/man2/open.2.html
-
@Christian-Ehrlicher said in QTemporaryFile: file not being created in Qt 5.11:
@koahnig said in QTemporaryFile: file not being created in Qt 5.11:
That is disputable.
Then please discuss this on the LKML, O_TMPFILE, when supported, doesn't create visible directory entry. As soon as you want it to be visible (= calling fileName()) this changes. See also e.g. here: http://man7.org/linux/man-pages/man2/open.2.html
That's fine and I agree with that.
But, if it worked one way in Qt 5.9 and works in a different way in 5.11, then it's a regression - so definitely a bug and also a high priority one.
-
Hi,
Can you post the link to the bug report ?
-
I have read both sides of this: the bug report + Qt documentation, and the Linux
open
docs forO_TMPFILE
. I can see both sides of the argument, and of course understand that Qt wants to use the OS facility.I admit I have not tried it, but how does, say, Qt docs stating stuff like
The file name of the temporary file can be found by calling fileName().
A temporary file will have some static part of the name and some part that is calculated to be unique.
and will be placed into the temporary path as returned by QDir::tempPath().marry with the
O_TMPFILE
docs ofCreate an unnamed temporary regular file
(2) can never be reached via any pathname
(4) do not require the caller to devise unique namesI am also intrigued that apparently the implementation has changed from Qt 5.9 to 5.11, I wonder why now.
It's easy for me to say, but some hints in the Qt docs about this possible behaviour might be welcome. I fully understand that it is not Qt's job to document everything which might be going on under each platform, but there are other precedents in the docs which do give the user a clue about platform-specific behaviour, or what to expect/not expect....
-
The support for O_TMPFILE was added in 5.10 and there was even a big changelog entry for this: https://code.qt.io/cgit/qt/qtbase.git/tree/dist/changes-5.10.0/?h=v5.10.0
-
@Christian-Ehrlicher said in QTemporaryFile: file not being created in Qt 5.11/5.12:
The support for O_TMPFILE was added in 5.10 and there was even a big changelog entry for this: https://code.qt.io/cgit/qt/qtbase.git/tree/dist/changes-5.10.0/?h=v5.10.0
Great, thanks for the link.
I'd still say there should be a note about this in Qt docs for Qt >5.10. Many other such OS "curiosities" are mentioned in the docs.
-
@sierdzio said in QTemporaryFile: file not being created in Qt 5.11/5.12:
I'd still say there should be a note about this in Qt docs
Feel free to provide a patch ;)
-
@Christian-Ehrlicher said in QTemporaryFile: file not being created in Qt 5.11/5.12:
@sierdzio said in QTemporaryFile: file not being created in Qt 5.11/5.12:
I'd still say there should be a note about this in Qt docs
Feel free to provide a patch ;)
Oh I wish, but no time right now.
I'll bookmark this, though and hopefully come back with a patch some day.
-
I'll bookmark this, though and hopefully come back with a patch some day.
Too late :) But you can review the patch: https://codereview.qt-project.org/c/qt/qtbase/+/282081
-
Great, thanks! Looks good. I may be lacking some powers as I don't see any +1 button I can click.
-
It's in the dialog you get when you hit the Reply button.
-
Ah OK found it under
REPLY
. That gerrit UI...