سؤال

I have 3 objects: a QWebView, a QPushButton and a QLineEdit.

My question is: how to create a connection where when i click the QPushButton, I get the url address in QLineEdit and so, load this url page in QWebView.

هل كانت مفيدة؟

المحلول

You will need to connect your worker slot to the clicked signal as follows:

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;
}

نصائح أخرى

connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(loadURL());


void loadURL(bool)
{
    ui->websitecaller->load(ui->lineEdit->text());
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top