I'm trying to save a stringlist of files into a specified directory. All I found was saveFileDialog where I save only one file at a time. Is there any other way to save multiple files into the target folder?
The QFileDialog ist for a user to choose a location for saving, not the actual saving process. How you save a list of files depends on what exactly you have, if you mean a QStringList of file locations you simply want to copy the easiest way would be something like this:
QStringList input_file_locations;
QString output_file_location = QFileDialog::getSaveFileName(...);
for (int i = 0; i < input_file_locations.size(); i++)
{
QFile::copy(input_file_locations.at(i), output_file_location + QString::number(i));
}
(I did non add the extraction and preservation of the actual file name to keep the example as simple as possible)
Related
I have few directorates and one file *.txt under one Directory A, Directory path is in QString
say c:/A/1/2/3/4
c:B/C/A/1/2/3/4/5/6
In my code I have only the full path, now I want to get the directory until A(name of A can change anytime) based on the file *.txt
inshort:- I want to parse all directory and get the directory until the place where *.txt present from right to left
Are you trying to get the string of the file path to A? Ex. If the file path was:
C:/Users/Admin/Desktop/file.txt
you want to get:
C:/Users
If so, all you have to do is find the second index location of "/". You could do something like this:
QString filePath = "C:/Users/Admin/Desktop/file.txt";
int index = filePath.indexOf("/");
index = filePath.indexOf("/",index+1);
QString shortenedPath = filePath.mid(0,index);
This should give you:
C:/Users/
If that isn't what you meant, then sorry for the long response.
I'm trying to read and edit a Desktop Entry .desktop file using Qt QSettings. The problem is that these files contain keys with multiple values separated by semicolon ;. I tried reading these as QStringList but no luck. I only get the first value. For example:
Keywords=disc;cdrom;dvd;burn;audio;video;
Categories=GTK;GNOME;AudioVideo;Audio;Video;DiscBurning;
MimeType=application/x-cd-image;application/x-cdrdao-toc;application/x-cue;application/x-toc;audio/x-scpls;audio/x-ms-asx;audio/x-mp3-playlist;audio/x-mpegurl;application/x-brasero;x-content/audio-cdda;x-content/video-dvd;x-content/video-vcd;x-content/video-svcd;x-content/image-picturecd;
Getting the values with:
settings.value("Desktop Entry/MimeType").toStringList();
settings.value("Desktop Entry/MimeType").toString();
returns only the first value (in my example: disc, GTK or application/x-cd-image).
How to I return the full value from those keys? And how do I write it back using QSettings?
Update (first attempt was completely useless)
Variant 1
QMap<QString, QString> settings;
QFile inFile("<input filename.ini>");
if(inFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inFile);
while (!in.atEnd())
{
QString line = in.readLine();
QStringList linelist = line.split("=");
settings[linelist[0]] = linelist[1];
}
}
Variant 2
use QSettings::registerFormat().
This is probably the only "clean" way to do it with QSettings. The advantage is that you can register it with the .desktop extension. You'll have to write a pair of ReadFunc() and WriteFunc() functions.
I think you can't do it. QSettings has certain interpretation of .ini file format, which is very close to Windows interpretation, and is not meant for generic parsing. Semicolon starts a comment, and apparently QSettings allows comment after value until end of line, and AFAIK there's no way around it.
You need to find a different library to handle .desktop files, or implement one yourself.
I am trying to save an image to server.Server directory structure is as follows
httpdocs-
Folder-
Page.aspx
and
httpdocs-
Images-
Subimages
The Folder and Images are under the httpdocs. I need to save the image to subimages folder from pages.aspx. Saving image code is on pages.aspx.
I tried
string CroppedImagePath = Server.MapPath("~/Images/Subimages"+file)
But not get the exact result
Unless file contains a leading / character, that's going to end up saving as something like:
~/Images/Subimagesfilename.ext
Use Path.Combine() to build a path name. Something like this:
var CroppedImagePath = Path.Combine(Server.MapPath("~/Images/Subimages"), file);
try this
string CroppedImagePath = Server.MapPath("~/Images/Subimages/"+file)
/ after Subimages
I'm building a simple file browser using QT, and I can't seem to get the setRootPath() of my model to be set to a file, rather than just a directory.
Ex:
setRootPath("/Users/Foo/Bar") works, but
setRootPath("/Users/Foo/Bar/readme.txt") simply sets the root path to "."
Not sure what I'm missing. Everything else within my application works fine.
You can do this:
QFileInfo m_FileInfo = QString("C:/Users/Foo/Bar/readme.txt");
setRootPath(m_FileInfo.absolutePath());
What we're doing is using QFileInfo to get the absolutePath() of the file. So it'll set the root path to C:/Users/Foo/Bar.
I have 3 jars: jar1, jar2 and jar3, in the same path who can change in other pc (ex: c:\prova)
When I run jar1, it moves jar2 in the Windows Sturtup folder.
I want that jar2 simply activate jar3 at every windows startup, but of course it doesn't find jar3 who is remained in the first path.
So I want that jar1 pass a reference (in this case the path c:\prova) to the jar2, when moving it, or at least on the first call to it.
I find it difficoult because:
I can't write the path in a text file in jar2: text files in jars aren't writable.
I can't write the text file in the windows Startup folder: it will be opened at every win startup..
I can't pass the path as a parameter, it will be good for the first call but I can't store this value for the succesive calls.
Sorry for my bad english, thanks for any help!
To add the file Path.txt (with jar3's path) in jar2:
Runtime.getRuntime().exec("jar uf jar2.jar Path.txt");
To read the file in jar2 (Startup is my class name):
String s = "/Path.txt";
is = Startup.class.getResourceAsStream(s);
br = new BufferedReader(new InputStreamReader(is));
while (null != (line = br.readLine())) {
list.add(line);
}
Thank me!