There are two QFile-pointer pointing to the same file, they belong different threads. One writes data to the file, the other reads. But I want to have only one operation going on, read or write.
if(!this->file->exists()) {
qDebug()<<"The file is not exists";
}
if(this->file->isOpen()) {
qDebug()<<"The file is open";
}
Let me put it another way: how to check whether the file in opened?
I test file.isOpen()? It doesn’t work. How can I do that?
Sounds like to me you’re trying to use isOpen to see if another thread has the same file open. AFAIK isOpen just tells you if the current QFile instance has a file open, not other QFile instances.
The only way I’m aware of being able to prevent different threads from reading and/or writing the same file is with file locking.
Not too sure if Qt has a way of doing this without having to delve into the more OS dependent APIs.