Howto在QString中存储HTML代码时,默认浏览器中打开HTML页面

Howto open html page in default browser, when html code is stored in QString

本文关键字:HTML 默认浏览器 页面 代码 QString 存储 Howto      更新时间:2023-10-16

我的QT应用程序应打开 HTML页面(使用默认浏览器,例如IE)。此HTML代码存储在QString中。

打开此"文件"的最佳方法是什么?

我只有内容?

QTemporaryFile是答案吗?还是可以更轻松地做到这一点?

QString content = "<html>...</html>";
?
QDesktopServices::openUrl(QUrl("..."));

qtemporaryfile方法是迄今为止完成任务的最简单的方法。

我看不到其他任何方法,然后使用ActiveQT进行一些" vodoo",如果有效。

最好的问候。

编辑:示例

QString htmlData; // your HTML data here
// The six Xs are actually required.
QTemporaryFile tmpFile( QLatin1String( "thefileXXXXXX.html" ) );
tmpFile.open();
QTextStream out( &tmpFile )
out << htmlData;
tmpFile.close();
QDesktopServives::openUrl( QUrl::fromLocalFile( tmpFile.fileName() ) );