Changes to QTemporaryFile since Qt 5.10.

On Linux, QTemporaryFile will attempt to create unnamed temporary
files. If that succeeds, open() will return true but exists() will be
false. If you call fileName() or any function that calls it,
QTemporaryFile will give the file a name, so most applications will
not see a difference.

To get a real file on disk call fileName().
This commit is contained in:
Roman Telezhynskyi 2021-02-17 19:20:25 +02:00
parent c8f12690bc
commit c1b7fcd2c9
3 changed files with 40 additions and 0 deletions

View File

@ -59,6 +59,16 @@ void DumpVector(const QVector<T> &points, const QString &templateName=QString())
if (temp.open())
{
#if defined(Q_OS_LINUX)
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// On Linux, QTemporaryFile will attempt to create unnamed temporary
// files. If that succeeds, open() will return true but exists() will be
// false. If you call fileName() or any function that calls it,
// QTemporaryFile will give the file a name, so most applications will
// not see a difference.
temp.fileName(); // call to create a file on disk
#endif
#endif
QJsonObject vectorObject;
VectorToJson(points, vectorObject);
QJsonDocument vector(vectorObject);

View File

@ -67,6 +67,16 @@ void DumpPassmarkData(const VPiecePassmarkData &data, const QString &templateNam
if (temp.open())
{
#if defined(Q_OS_LINUX)
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// On Linux, QTemporaryFile will attempt to create unnamed temporary
// files. If that succeeds, open() will return true but exists() will be
// false. If you call fileName() or any function that calls it,
// QTemporaryFile will give the file a name, so most applications will
// not see a difference.
temp.fileName(); // call to create a file on disk
#endif
#endif
QJsonObject dataObject
{
{"data", data.toJson()},
@ -92,6 +102,16 @@ void DumpPassmarkShape(const QVector<QLineF> &shape, const QString &templateName
if (temp.open())
{
#if defined(Q_OS_LINUX)
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// On Linux, QTemporaryFile will attempt to create unnamed temporary
// files. If that succeeds, open() will return true but exists() will be
// false. If you call fileName() or any function that calls it,
// QTemporaryFile will give the file a name, so most applications will
// not see a difference.
temp.fileName(); // call to create a file on disk
#endif
#endif
QJsonObject shapeObject
{
{"shape", PassmarkShapeToJson(shape)},

View File

@ -1178,6 +1178,16 @@ void VPiece::DumpPiece(const VPiece &piece, const VContainer *data)
temp.setAutoRemove(false); // Remove dump manually
if (temp.open())
{
#if defined(Q_OS_LINUX)
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// On Linux, QTemporaryFile will attempt to create unnamed temporary
// files. If that succeeds, open() will return true but exists() will be
// false. If you call fileName() or any function that calls it,
// QTemporaryFile will give the file a name, so most applications will
// not see a difference.
temp.fileName(); // call to create a file on disk
#endif
#endif
QJsonObject testCase
{
{"bd", piece.DBToJson(data)},