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. Verify directories are the same, string compare is not working
Qt 6.11 is out! See what's new in the release blog

Verify directories are the same, string compare is not working

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.7k 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    I have a dialog I am adding drag and drop to. I drag a file into my dialog and it gives me the path:

    file:///home/fcarney/Desktop/nospam.txt
    

    However, if I use QUrl and dissect this I get this from path():

    ///home/fcarney/Desktop/nospam.txt
    

    From another part of my program I have another path:

    /home/fcarney/Desktop/nospam.txt
    

    Obviously a string compare will not work here. So is there something in QFile or QFileInfo that lets me check equivalency of paths? I store both paths as QUrls, but I only set the scheme for one of them. Maybe that is where I am going wrong. My check however starts out checking strings. So maybe that part needs to change too.

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @fcarney said in Verify directories are the same, string compare is not working:

      if I use QUrl and dissect this I get this from path():

      You're using the wrong function - it's a local file so you should use toLocalFile() ...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      fcarneyF 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        @fcarney said in Verify directories are the same, string compare is not working:

        if I use QUrl and dissect this I get this from path():

        You're using the wrong function - it's a local file so you should use toLocalFile() ...

        fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        @Christian-Ehrlicher If it is missing the scheme then it won't return anything.

        I ended up doing this to check my wonky paths:

        bool FileTransferBroker::pathsEqual(QString source, QString dest)
        {
            QFileInfo fsrc(source);
            QFileInfo fdst(dest);
        
            return fsrc.absoluteFilePath() == fdst.absoluteFilePath();
        }
        

        I honestly am unsure how I got the /// path as I cannot get it to repeat this again.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @fcarney said in Verify directories are the same, string compare is not working:

          If it is missing the scheme then it won't return anything.

          Then you build up your url wrong.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          fcarneyF 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @fcarney said in Verify directories are the same, string compare is not working:

            If it is missing the scheme then it won't return anything.

            Then you build up your url wrong.

            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            @Christian-Ehrlicher said in Verify directories are the same, string compare is not working:

            Then you build up your url wrong.

            I had to go back through and convert all my local paths to file:// at the start and build urls from there. The pathEqual function works so I kept it. So I had a couple of problems here.

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            1

            • Login

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