Use std::string for string manipulation.
Use std::string for string manipulation.
God I knew I had to do this...
Ok, Thanks
Ok, I found out that you cant create directories with iostream.
I found the class QDir, but I dont know how to create a directory...
I tried it with:
Qt Code:
if (!Dir->exists()) { Dir->mkdir("../logs/"); }To copy to clipboard, switch view to plain text mode
And with Dir->mkdir("logs"); , ... and so on. But a directory was never created.
How to do this???
The directory should be created in the same directory where my applications runs.
How can I get the relative path or the absolute directory?
Usually I understand the QT Documentation, but with QDir I got some problems in understanding.
Absolute path is one starting with the root of the filesystem ("/"), relative is everything else. So if you are currently in "/a/b/c" and ask for the directory "d" then "d" is a relative path and "/a/b/c/d" is an absolute path both pointing to the same resource.
I have already read the differnce between absolut and relative. (And I think I understood the difference, its not that complicated)
But I dont know how to work with them.
For Example, why doesnt work my Code below?
Qt Code:
if (!Dir->exists()) { Dir->mkdir(test); }To copy to clipboard, switch view to plain text mode
With the command absoluteFilePath("t") I get the absolute path where my directory should be.
But my Directory still isnt created.
Your code is invalid. Call QDir::mkdir() with "t" and not the value of test. And don't create QDir objects on the heap, it's not java.
Qt Code:
if (!Dir.exists()) { Dir.mkdir("t"); }To copy to clipboard, switch view to plain text mode
Still doesnt work?! I begin hardly feeling stupid...
What does Dir.absolutePath() return?
By the way, your code still doesn't make much sense - it says "if in the current directory there is no 'logs' subdirectory, create a 't' subdirectory". Is that really what you want?
Yeah I know the code doesnt make much sense, but I tried at least to create a Directory. In my finished programm it will create a sub folder called "logs".
With Dir.absolutePath() I get: /home/marco/workspace/IPA/build/logs/t
But in Build there is no folder called "logs" or "t".
Maybe I need root rights or something like that?
I could also post my whole programm but its large :S
I'm not sure how would you want to create a subdirectory of a directory that doesn't exist...
Qt Code:
#include <QDir> #include <QtDebug> int main(){ qDebug() << "Dir:" << dir.absolutePath(); qDebug() << "Exists:" << dir.exists(); if(!dir.exists()){ // if dir doesn't exist, you can't create a subdirectory in it // [1] qDebug() << "Current dir:" << dir.absolutePath(); if(dir.exists()){ qDebug() << "Current dir exits..."; dir.mkdir("logs"); } // [2] // dir.mkpath("logs"); } qDebug() << "Exists:" << dircheck.exists(); return 0; }To copy to clipboard, switch view to plain text mode
Use either [1] or [2].
GonzoFist (20th April 2010)
Bookmarks