Reputation: 3174
I wanted to make a window and add a QTabWidgets with the widgets I want to it. So I followed the Qt TabDialog example and from what I know, I followed the same path as in the example. Problem is I get this error while trying to add my widgets as tabs: "/home/user/Programming/C++/QtTests/TabExample/TabExample-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Release/../TabExample/tabwidget.cpp:20: error: no matching function for call to 'QTabWidget::addTab(Tab_One*, QString*&)'". Why do I get this error because Tab_One is inherited from QWidget? Here is my main widget code:
Header file:
#ifndef TABWIDGET_H
#define TABWIDGET_H
#include <QWidget>
class QTabWidget;
class Tab_One;
class Tab_Two;
class QString;
class QHBoxLayout;
class QDialog;
class TabDialog : public QDialog {
Tab_One *firstTab;
Tab_Two *secondTab;
QTabWidget *myTabWidget;
QString *labelTabOne;
QString *labelTabTwo;
QHBoxLayout *layout;
public:
TabDialog(QWidget *parent = NULL);
};
#endif // TABWIDGET_H
and source file:
#include <QWidget>
#include <QDialog>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QString>
#include "tabwidget.h"
#include "tab1.h"
#include "tab2.h"
TabDialog::TabDialog(QWidget *parent) : QDialog(parent)
{
layout = new QHBoxLayout;
labelTabOne = new QString("My First Tab");
labelTabTwo = new QString("My Second Tab");
myTabWidget = new QTabWidget;
firstTab = new Tab_One;
secondTab = new Tab_Two;
myTabWidget->addTab(firstTab, labelTabOne);
myTabWidget->addTab(secondTab, labelTabTwo);
layout->addWidget(myTabWidget);
setLayout(layout);
}
and here is one of my widets(tab1): header:
#ifndef TAB1_H
#define TAB1_H
#include <QWidget>
class QVBoxLayout;
class QPushButton;
class Tab_One : public QWidget {
QPushButton *button_one;
QPushButton *button_two;
QVBoxLayout *layout;
public:
Tab_One(QWidget *parent = NULL);
};
#endif // TAB1_H
and source:
#include <QWidget>
#include <QDialog>
#include <QTabWidget>
#include <QHBoxLayout>
#include <QString>
#include "tabwidget.h"
#include "tab1.h"
#include "tab2.h"
TabDialog::TabDialog(QWidget *parent) : QDialog(parent)
{
layout = new QHBoxLayout;
labelTabOne = new QString("My First Tab");
labelTabTwo = new QString("My Second Tab");
myTabWidget = new QTabWidget;
myTabWidget->addTab(new Tab_One(this), labelTabOne);
myTabWidget->addTab(new Tab_Two(this), labelTabTwo);
layout->addWidget(myTabWidget);
setLayout(layout);
}
Thank you very much and sorry for the long post
Upvotes: 3
Views: 5480
Reputation: 8788
The problem isn't your tab, but the QString. QTabWidget::addTab()
expects a const reference to a QString, but you're giving it a pointer to a QString. Try using the dereference operator (*
), like this:
myTabWidget->addTab(firstTab, *labelTabOne);
myTabWidget->addTab(secondTab, *labelTabTwo);
Upvotes: 5