Graham Labdon schreef op 23-2-2015 om 10:48:
> Hi
>
> I am trying to use QLockFile in a function that receives a file path as a 
> QString.
>
> When I pass the string directly to the constructor of QLockFile and the call 
> tryLock it always fails.
>
> However, if I hard code the string the lock succeeds (although I get compiler 
> warnings about unknown escape sequences)
>
> If I user the toNativeSeparators method of QDir on my file path the call to 
> tryLock fails although in the debugger the value of the converted string 
> appears to the same as the hard coded value.
>
> I would be grateful if someone could explain this behaviour
>
> FileDestination::FileDestination(const QString& filePath)
> {
>      QLockFile lockFile(filePath); // tryLock fails
>
>      QString s = QDir::toNativeSeparators(filePath)
>      QLockFile lockFile2(s); // tryLock fails
>
>      QLockFile lockFile3("C:\jobs\Myjob.txt"); // tryLock succeeds bu get 
> compiler warnings for unknown escape sequences
> }

The last one is not valid. A \ in a C/C++ string is an escape character. 
If you want a literal \ in your string, you need to double them. Or, in 
Qt, you just use forward slashes (/) on all platforms.

So, are you sure your filePath itself is valid?

André

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to