PDA

View Full Version : Open odt files with Qt



Qiieha
20th April 2011, 17:04
Hi
I want open an odt file with my application.
I have already opened pdf files- > this works without problems with the

QDesktopServices::openUrl(QUrl("file:///path, QUrl::TolerantMode);

but if I open an odt file with that command, it seems to open it, because the openoffice picture with the progressbar pops up, but the file stay closed....

whats wrong?

can u help me ? thanks

mcosta
21st April 2011, 09:52
For me it works (I tried only in Windows).

Are your environment configured to launch OpenOffice Writer to read ODT files?

Can you post the code?

This in my code



// Ask the user to select a ODT file
void Widget::on_openUrlButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName (
this,
tr ("Open File"),
".",
tr ("Open Document Text Files (*.odt)"));

if (!fileName.isEmpty ()) {
ui->urlEdit->setText (fileName);
}
}

// Launch proper application to read selected file
void Widget::on_goButton_clicked()
{
QUrl url = QUrl::fromLocalFile (ui->urlEdit->text ());

bool result = QDesktopServices::openUrl (url);
if (!result)
qWarning () << "Failed to open URL " << url;
}

Qiieha
21st April 2011, 10:29
Thank u for your reply. I'm on ubuntu, but your reply helped great. There where too much slashes in my code. It was my mistake :( . But if I create my QUrl like you, the problem had not ever occured.