0

这应该很容易,但是有些东西不起作用,我找不到问题。

我有两个类,如下所示:

1) 个人选项卡

#ifndef INDIVIDUALTAB_H
#define INDIVIDUALTAB_H

#include <QMainWindow>
#include <QInputDialog>
#include <QTableWidget>
#include <QVBoxLayout>
#include <QLabel>

class IndividualTab : public QWidget
{
    Q_OBJECT

public:
    IndividualTab(QWidget *parent = 0);
    QTableWidget *table;
    QVBoxLayout *layout;

};
#endif // INDIVIDUALTAB_H


IndividualTab::IndividualTab(QWidget *parent) : QWidget()
{
    table = new QTableWidget(0,4);
    layout = new QVBoxLayout();
}

2) 二等舱

#ifndef SECONDCLASS_H
#define SECONDCLASS_H

#include "individualtab.h"

class secondClass : public QMainWindow
{
    Q_OBJECT

public:
    explicit secondClass(QWidget *parent = 0);
    Ui::secondClass *ui;
    ~secondClass();

    QList<IndividualTab> *individualTabList;
};
#endif // SECONDCLASS_H


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


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

void secondClass::addNewItem()
{
    //Getting parameters
    QList<QString> parameters;
    //creating QList

    //Updating individualTab
    for(int i = 0; i < ui->tabWidget->count(); i++)
    {
        if(parameters.at(0) == ui->tabWidget->tabText(i))
        {
            IndividualTab tab = individualTabList->at(i);
            tab.addItem(parameters);
            break;
        }
 }
}

当我编译我有这个错误:

In file included from ../secondclass.h:5:0,
                 from ../secondclass.cpp:1:
/usr/include/qt4/QtGui/qwidget.h: In copy constructor 'IndividualTab::IndividualTab(const IndividualTab&)':
/usr/include/qt4/QtGui/qwidget.h:806:5: error: 'QWidget::QWidget(const QWidget&)' is private
../individualtab.h:10:7: error: within this context
../secondclass.cpp: In member function 'void SecondClass::addNewItem()':
../secondclass.cpp:142:56: note: synthesized method 'IndividualTab::IndividualTab(const IndividualTab&)' first required here 

我坚持认为问题出在IndividualTab tab = individualTabList->at(i); 所以我换了

IndividualTab *tab = new IndividualTab();
tab = individualTabList->at(i);

但在这种情况下,我有这个错误:

../secondclass.cpp: In member function 'void SecondClass::addNewItem()':
../secondclass.cpp:143:42: error: cannot convert 'const IndividualTab' to 'IndividualTab*' in assignment
../secondclass.cpp:144:17: error: request for member 'addItem' in 'tab', which is of non-class type 'IndividualTab*'
In file included from ../secondclass.h:5:0,
                 from ../secondclass.cpp:1:
/usr/include/qt4/QtGui/qwidget.h: In copy constructor 'IndividualTab::IndividualTab(const IndividualTab&)':
../individualtab.h:10:7:   instantiated from 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = IndividualTab]'
/usr/include/qt4/QtCore/qlist.h:512:13:   instantiated from 'void QList<T>::append(const T&) [with T = IndividualTab]'
../Ripetizioni/secondclass.cpp:112:38:   instantiated from here
/usr/include/qt4/QtGui/qwidget.h:806:5: error: 'QWidget::QWidget(const QWidget&)' is private
../individualtab.h:10:7: error: within this context
In file included from /usr/include/qt4/QtCore/qobject.h:50:0,
                 from /usr/include/qt4/QtGui/qwidget.h:46,
                 from /usr/include/qt4/QtGui/qmainwindow.h:45,
                 from /usr/include/qt4/QtGui/QMainWindow:1,
                 from ../secondclass.h:4,
                 from ../secondclass.cpp:1:
/usr/include/qt4/QtCore/qlist.h: In member function 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = IndividualTab]':
/usr/include/qt4/QtCore/qlist.h:372:58: note: synthesized method 'IndividualTab::IndividualTab(const IndividualTab&)' first required here 

提前致谢!

4

1 回答 1

3

QWidgets 不是用来复制的。你individualTabList应该是一个指向-的容器IndividualTab。并且没有充分的理由将该成员本身作为指针。将声明更改为:

 QList<IndividualTab*> individualTabList;

那么你也能:

IndividualTab *tab = individualTabList.at(i);
于 2012-05-06T09:29:18.357 回答