QTemporaryFile bug

Discuss anything related to product development
Post Reply
seasoned_geek
Posts: 254
Joined: Thu Jun 11 2020 12:18 pm

QTemporaryFile bug

Post by seasoned_geek »

If there is an official bug database please let me know and I will put this there along with the malloc crash thing I reported earlier.

From the doc, Detailed Description section

Code: Select all

// Within a function/method
QTemporaryFile file;
if (file.open()) {
   // file.fileName() returns the unique file name
}
// QTemporaryFile destructor removes the temporary file as it goes out of scope.
I was having no end of trouble getting a temporary file to work in my Diamond editor coding today. So, I changed my "Hello World!" program to have the following.

Code: Select all

void Task::run()
{
    // Do processing here

    qDebug() << "Hello World!";

    QTemporaryFile file(this);

    if (file.open())
    {
        qDebug() << "temporary file name: " << file.fileName();
    }
    else
    {
        qDebug() << "failed to open temporary file";
    }

    emit finished();
}
Build it, run it, and have the exact same problem.

Code: Select all

roland@roland-amd-desktop:~/Projects/cs_hello_debug$ ./cs_hello
Hello World!
QFSFileEngine::open() No file name specified
failed to open temporary file
roland@roland-amd-desktop:~/Projects/cs_hello_debug$ 

I was trying to use a template name so I could keep the original file extension (i.e. .cpp). At first I thought this was just a problem with template names, but it appears QTemporaryFile doesn't work at all. Just for grins I tried a non-parented version and got the same results.

Code: Select all

void Task::run()
{
    // Do processing here

    qDebug() << "Hello World!";

    QTemporaryFile file;

    if (file.open())
    {
        qDebug() << "temporary file name: " << file.fileName();
    }
    else
    {
        qDebug() << "failed to open temporary file";
    }

    emit finished();
}

Code: Select all

roland@roland-amd-desktop:~/Projects/cs_hello_debug$ ./cs_hello
Hello World!
QFSFileEngine::open() No file name specified
failed to open temporary file
roland@roland-amd-desktop:~/Projects/cs_hello_debug$ 

seasoned_geek
Posts: 254
Joined: Thu Jun 11 2020 12:18 pm

Re: QTemporaryFile bug

Post by seasoned_geek »

Just an FYI, QTemporaryDir works well.

Code: Select all

void Task::run()
{
    // Do processing here

    qDebug() << "Hello World!";

    QTemporaryDir d;

    if (d.isValid())
    {
        qDebug() << "temporary dir name: " << d.path();
    }
    else
    {
        qDebug() << "failed to create temporary dir";
    }

    emit finished();
}

Code: Select all

roland@roland-amd-desktop:~/Projects/cs_hello_debug$ ./cs_hello
Hello World!
temporary dir name:  /tmp/cs_hello-1ZTvii
roland@roland-amd-desktop:~/Projects/cs_hello_debug$ 

barbara
Posts: 447
Joined: Sat Apr 04 2015 2:32 am
Contact:

Re: QTemporaryFile bug

Post by barbara »

If there is an official bug database please let me know and I will put this there along with the malloc crash thing I reported earlier.
We have noted your issues with QTemporaryFile and the malloc problem and someone on the CS development team will be reviewing them. Both items have been verified as valid concerns.

Thanks for reporting.

Barbara
Post Reply