将小部件插入Tab小部件的选项卡中

时间:2016-02-01 19:32:43

标签: c++ qt tabwidget

我在Tab Widget中将小部件插入选项卡时遇到问题。因为我尝试使用标签创建一个简单的Web浏览器,所以我创建了一个带有一些pushButtons和WebView的小部件,但是当我想将widget添加到我动态创建的选项卡中时(在代码中显示)它会抛出两个错误:

  

mainwindow.obj:-1:错误:LNK2019:未解析的外部符号" public:__ cdecl浏览::浏览(类QWidget *)" (?? 0Browsing @@ @ QEAA @@@ PEAVQWidget Z)
  在函数中引用" private:void __cdecl MainWindow :: on_tabWidget_tabBarDoubleClicked(int)" (?on_tabWidget_tabBarDoubleClicked @ @@ MainWindow的AEAAXH @ Z ***)

  

debug \ Pluto.exe:-1:错误:LNK1120:1个未解析的外部。

browsing.cpp:

    #include "browsing.h"
    #include "ui_browsing.h"
    #include <QWidget>
    #include <QtWebKitWidgets/QWebView>

    Browsing::Browsing(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Browsing)
    {
        ui->webView->load(QString("http://google.com"));
        ui->setupUi(this);
    }

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

    void Browsing::on_backButton_clicked()
    {
        ui->webView->back();
    }

    void Browsing::on_forwardButton_clicked()
    {
        ui->webView->forward();
    }

    void Browsing::on_reloadButton_clicked()
    {
        ui->webView->reload();
    }


    void Browsing::on_searchLine_returnPressed()
    {
        ui->webView->load(QString("http://"+ui->searchLine->text()));
    }

mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "browsing.h"

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

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

    void MainWindow::on_tabWidget_tabCloseRequested(int index)
    {
        ui->tabWidget->removeTab(index);
    }

    void MainWindow::on_tabWidget_tabBarDoubleClicked(int index)
    {
        //ui->tabWidget->insertTab(ui->tabWidget->count(),new Browsing(),QIcon(QString("")),"New tab"); -- also not working
        ui->tabWidget->insertTab(ui->tabWidget->count(),new Browsing(new QWidget(ui->tabWidget)),"New Tab");
        ui->tabWidget->setCurrentIndex(index + 1);
    }

    void MainWindow::on_addButton_clicked()
    {
        //ui->tabWidget->insertTab(ui->tabWidget->count(),new Browsing(),QIcon(QString("")),"New tab");
        ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);

    }

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_tabWidget_tabCloseRequested(int index);

    void on_tabWidget_tabBarDoubleClicked(int index);

    void on_addButton_clicked();

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H

Browsing.h:

    #ifndef BROWSING_H
#define BROWSING_H

#include <QWidget>

namespace Ui {
class Browsing;
}

class Browsing : public QWidget
{
    Q_OBJECT

public:
    explicit Browsing(QWidget *parent = 0);
    ~Browsing();

private slots:
    void on_backButton_clicked();

    void on_forwardButton_clicked();

    void on_reloadButton_clicked();

    void on_searchLine_returnPressed();

private:
    Ui::Browsing *ui;
};

#endif // BROWSING_H

0 个答案:

没有答案