Solved Verify directories are the same, string compare is not working
-
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.
-
@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() ...
-
@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.
-
@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.
-
@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.