[Interest] QLockFile

André Somers andre at familiesomers.nl
Mon Feb 23 11:44:01 CET 2015


Graham Labdon schreef op 23-2-2015 om 11:36:
> Hi
>
> QString path = "C:\jobs\Test1\job.xcfg";
> QFile file(path);
>
> bool res = file.open(QIODevice::WriteOnly);
>
> here res is true

But, the path is once again wrong. Use \\ or /, but not \ in string 
literal paths.
>
> BUT
>
> QString path = "C:\jobs\Test1\job.xcfg";
> QLockFile lock(path);
>
> bool res = lock.tryLock();
>
> here res is false
>
> BUT
> QLockFile lock("C:\jobs\Test1\job.xcfg");
>
> bool res = lock.tryLock();
>
> here res is true!

And you are sure that you are only locking once? And what does error() 
return when tryLock fails?

André

P.S. Please keep the discussion on the list, not in private mail.

>
> Thanks for your time
> -----Original Message-----
> From: interest-bounces+graham.labdon=avalonsciences.com at qt-project.org [mailto:interest-bounces+graham.labdon=avalonsciences.com at qt-project.org] On Behalf Of André Somers
> Sent: 23 February 2015 10:15
> To: interest at qt-project.org
> Subject: Re: [Interest] QLockFile
>
> Graham Labdon schreef op 23-2-2015 om 11:10:
>> Yes I am sure
>> I have tried this with numerous file locations and different ways of constructing a QLockFile and the ONLY on that works is if I hard code an non escaped file path.
> The non-escaped path will point to a different location than what you think it points to. That may be why that one succeeds.
>
> I have used QLockFile successfully (with "dynamic" paths). So, there really is something wrong with your way of using it, not with QLockFile itself.
>
> Did you try opening a file yourself at the location you want from code using QFile and opening it write only? What happens if you do that?
>
> André
>
>> -----Original Message-----
>> From: André Somers [mailto:andre at familiesomers.nl]
>> Sent: 23 February 2015 10:07
>> To: Graham Labdon
>> Subject: Re: [Interest] QLockFile
>>
>> Graham Labdon schreef op 23-2-2015 om 11:00:
>>> Hi
>>> The filePath is definitely valid
>>>
>>> The only way I can get QLockFile to work at the moment is by hard coding an invalid c string as in my example.
>>>
>>> If I use double backslashes in the hard code version tryLock fails
>>>
>> Are you sure you can actually write at that location?
>>
>> André
>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest




More information about the Interest mailing list