Die classe
QString QFileInfo::absoluteFilePath () const
und
QString QDir::absolutePath () const
mit CDup von qdir geht man ueberall ihn....
machen den richtigen job je nach os ...
dann gibt es noch
QString QDir::currentPath () [static]
QString QDir::homePath () [static]
Ich finde nur probleme bei window file:/// lokal file da QUrl nicht automatisch interpretiert werden zu file:... mache ich einfach so....
IMO: vielleicht ist es besser im QT4.3 ....
Code: Alles auswählen
void OpenDesktop( QUrl loc )
{
#if defined Q_WS_MAC
/* direct mit open wegen dem finder */
QProcess *m = new QProcess();
QStringList macs;
macs << loc.toString(); /* oeffnet der default browser oder programm */
m->startDetached(QString("open") , macs );
///////std::cout << "OpenDesktop [" << qPrintable(macs.join(" ")) << "]" << std::endl;
return;
#endif
#if defined Q_WS_WIN
QString fullFileName = loc.toString();
if (fullFileName.startsWith("http://", Qt::CaseInsensitive) or
fullFileName.startsWith("https://", Qt::CaseInsensitive) or
fullFileName.startsWith("ftp://", Qt::CaseInsensitive) or
fullFileName.startsWith("news://", Qt::CaseInsensitive) or
fullFileName.startsWith("mailto:", Qt::CaseInsensitive) or
fullFileName.startsWith("webdav://", Qt::CaseInsensitive) )
{
/* all ok */
} else {
fullFileName.prepend("file:///");
}
bool wr = QDesktopServices::openUrl(QUrl(fullFileName));
if (!wr) {
QMessageBox::warning(0, tr("Error"),tr("Window Unable to open action file or dir %1").arg(loc.toString()));
}
return;
#endif
/* linux */
bool r = QDesktopServices::openUrl(loc);
if (!r) {
QMessageBox::warning(0, tr("Error"),tr("Linux Unable to open action file or dir %1").arg(loc.toString()));
}
}
und bei gewisse externe libs muss man bei window vielleicht die / umleiten zu \\ ....
.........................
speack português italiano deutsch english castellà qt