【问题标题】:Qt 4: How implement a "Go" button to the QWebViewQt 4:如何实现 QWebView 的“Go”按钮
【发布时间】:2014-04-06 16:04:22
【问题描述】:

我有 3 个对象:一个 QWebView、一个 QPushButton 和一个 QLineEdit。

我的问题是:如何创建一个连接,当我单击 QPushButton 时,我会在 QLineEdit 中获取 url 地址,因此,在 QWebView 中加载此 url 页面。

【问题讨论】:

  • Albert,问题现在解决了吗?
  • 是的,你的课对我有用。谢谢拉斯洛。

标签: c++ qt4 qwebview qlineedit qpushbutton


【解决方案1】:

您需要将您的工作槽连接到 clicked 信号,如下所示:

class MyClass : public QWidget
{
    Q_OBJECT
    public:
        explicit MyClass(QWidget *parent)
            : QWidget(parent)
            , myPushButton("Press Me", this)
            , QLineEdit(this)
            , myWebView(this)
        {
            connect(myPushButton, SIGNAL(clicked(bool)), SLOT(handleClicked(bool));
        }

    public slots:

    void handleClicked(bool)
    {
        myWebView->load(myLineEdit->text());
    }

    private:
        QWebView *myWebView;
        QLineEdit *lineEdit;
        QPushButton *myPushButton;
}

【讨论】:

    【解决方案2】:
    connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(loadURL());
    
    
    void loadURL(bool)
    {
        ui->websitecaller->load(ui->lineEdit->text());
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 2017-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      相关资源
      最近更新 更多