我需要能够QList<QRadioButton *> colorList
从 wager.cpp 访问在 mainwindow.h 中声明的内容。
我将在这里展示我目前的尝试。
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QTextEdit>
#include <QCheckBox>
#include <Qlist>
#include <QRadioButton>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void runButtonClicked();
private:
Ui::MainWindow *ui;
QPushButton *runButton;
QTextEdit * runText;
};
QList<QRadioButton *> colorList; // where should i put this??
#endif // MAINWINDOW_H
错误: LNK2005: "class QList colorList" (?colorList@@3V?$QList@PAVQRadioButton@@@@A) 已经在 main.obj 中定义
赌注.cpp
#include "wager.h"
#include "mainwindow.h"
#include "deck.h"
Wager::Wager()
{
}
void build_bet_lists()
{
for(int i=0;i<5;i++)
{
qDebug()<<colorList[i]->isChecked;
}
}
colorList 定义在
主窗口.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QRadioButton * street1BetBlack = new QRadioButton("Black");
QRadioButton * street2BetBlack = new QRadioButton("Black");
QRadioButton * street3BetBlack = new QRadioButton("Black");
QRadioButton * street4BetBlack = new QRadioButton("Black");
QRadioButton * street5BetBlack = new QRadioButton("Black");
QRadioButton * street1BetRed = new QRadioButton("Red");
QRadioButton * street2BetRed = new QRadioButton("Red");
QRadioButton * street3BetRed = new QRadioButton("Red");
QRadioButton * street4BetRed = new QRadioButton("Red");
QRadioButton * street5BetRed = new QRadioButton("Red");
QList<QRadioButton *> colorList;
colorList << street1BetBlack << street1BetRed << street2BetBlack << street2BetRed << street3BetBlack << street3BetRed << street4BetBlack << street4BetRed << street5BetBlack << street5BetRed ;
}