【问题标题】:I cant display html我无法显示html
【发布时间】:2016-07-18 23:25:25
【问题描述】:

所以,当我按下按钮时,我试图向 textbrowser 显示一个 html,但我收到一条消息:无法找到字符串文字运算符 'operator""https' with 'const char [38]', 'unsigned int'参数

这是我的代码

       #include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <stdio.h>
#include <qlayoutitem>
#include <QString>
#include <QCoreApplication>
#include <QDir>
#include <QtCore>
#include <QFileDialog>
#include <QDesktopServices>


using namespace std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}




void MainWindow::on_pushButton_clicked()
{

        ui->textBrowser->setText("<html><body><iframe src=\"https://drive.google.com/file/d/0B4k6aYtTLhHbamxJNGNqTDZqWHM/preview\" width=\"640\" height=\"480\"></iframe></body></html>");


}

void MainWindow::on_pushButton_4_clicked()
{
    QString link = "https://docs.google.com/forms/d/e/1FAIpQLSdazoZx2TpWblMfrvZGJwgvPl8qz4Ftxb0aOkht2bfUSklXcw/viewform";
    QDesktopServices::openUrl(QUrl(link));

}

void MainWindow::on_pushButton_3_clicked()
{
    QString link = "https://docs.google.com/forms/d/e/1FAIpQLSdazoZx2TpWblMfrvZGJwgvPl8qz4Ftxb0aOkht2bfUSklXcw/viewform";
    QDesktopServices::openUrl(QUrl(link));

}


void MainWindow::on_pushButton_5_clicked()
{
    QString link = "https://docs.google.com/forms/d/e/1FAIpQLSdazoZx2TpWblMfrvZGJwgvPl8qz4Ftxb0aOkht2bfUSklXcw/viewform";
    QDesktopServices::openUrl(QUrl(link));

}

【问题讨论】:

  • 你必须转义字符串中的引号
  • 等等..在哪一行?
  • 你的代码中只有一个字符串,所以..
  • 大声笑 - 不会发生这样的事情,你需要阅读有关 c++ 编程的基本书籍,请参阅字符串文字部分
  • @pm100 我知道 c++ 但不会 QT。

标签: c++ qt


【解决方案1】:

转义引号

void MainWindow::on_pushButton_clicked()
{
   ui->textBrowser->setText("<html><body><iframe src=\"MY GOOGLE DRIVE EMBED LINK\" width=\"640\" height=\"480\"></iframe></body></html>");


}

我还注意到您发布的代码不是失败的代码 - 请尝试发布真实代码

【讨论】:

  • 不起作用:((我的应用程序打开了,但是当我按下加载文件时它只是空白。
  • 是的,它确实有效,现在您遇到了不同的问题。问一个新问题
  • 我还没有发布的其余按钮是当我按下它们时会在默认浏览器上打开一个完美运行的链接。是的,但我不知道是什么问题,你能帮忙吗?我可以在 Skype 上共享屏幕。
  • 我试图粘贴它,但它说它太长了。我应该创建一个新帖子吗?
  • @Lambros 是的,也不是。新问题,但将您的超长代码减少到可能导致您的问题的最少代码。将您的代码减少到最低限度将向您显示错误的确切位置以及如何修复它的可能性很大。如果没有,您将获得所有“帮助修复我的代码”问题所需的 minimal reproducible example
【解决方案2】:

问题出在这里:

ui->textBrowser->setText("<html><body><iframe src="MY GOOGLE DRIVE EMBED LINK" width="640" height="480"></iframe></body></html>");

有两种解决方案:

1) 转义内部双引号:

ui->textBrowser->setText("<html><body><iframe src=\"MY GOOGLE DRIVE EMBED LINK\" width=\"640\" height=\"480\"></iframe></body></html>");

2) 用单引号替换内部双引号:

ui->textBrowser->setText("<html><body><iframe src='MY GOOGLE DRIVE EMBED LINK' width='640' height='480'></iframe></body></html>");

【讨论】:

猜你喜欢
  • 2013-04-11
  • 2022-01-05
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
  • 2021-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多