Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QLockFile
Forum Updated to NodeBB v4.3 + New Features

Using QLockFile

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    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
    

    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      @"C:\jobs\Myjob.txt"@
      You have two escape sequences here \j and \M which don't exist. You would have to double the backslashes to create a valid path.

      Out of curiosity why don't you use the unix notation since you are using Qt ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #3

        Hi thanks for the reply
        I appreciate why I get the compile warnings, but this is the only version that works.
        The incoming filePath argument has unix notation but the call to tryLock fails

        This is confusing

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved