Bear with me, I am new to CPP and am having a problem with variables. The only reason I haven\'t given up yet, is because of the support I got off this board so far!!
I have a Class called \"HandMade\" . Handmade is derived from QVBox class. Handmade includes a listbox, a slider, an ADD button, a REMOVE button. When you press ADD, whatever value the slider displays is added to listbox. When you press delete, whatever value is current in the listbox is deleted from list box.
The HandMade class also includes another class “TicTacToeâ€. Basically this is the last item in the QVBox.
(As you can tell, I just slapped TWO example programs into ONE to learn some fundamentals!!)
Now, it all works!! The buttons update the listbox from the slider etc.. And the tictactoe game works right along below it. Kind of 2 independent widgets functioning on the same page.
Now HOW Can I get the TicTacToe class to TALK TO the LISTBOX in HandMade class? For example, when I tap a box in the TicTacToe grid (call it TTT) a mousePressEvent is generated. In TTT, the mouseevent calls a function to draw the X or O etc.. This all works fine.
I want to add something to the mousePressEvent that will also ADD TO THE LISTBOX a number from 1 to 9.
The 2 class files are listed below my signature.
Note that in HandMade *lb is a variable to reference the listbox.
I assume if “lb†was global or accessable I could just do:
lb->insertItem( “9†);
But that doesn’t work inside the Class TicTacToe!
I just get this error message:
Error E2451 tictactoe.cpp 50: Undefined symbol \'lb\' in function TicTacToe::mousePressEvent(QMouseEvent *)
Anyone care to help a newbie learn about this!!
Thankx in advance
JDF
***** handmaid.h ********
#ifndef HANDMADE_H
#define HANDMADE_H
// My main widget is derived from the QVBox widget
#include <qvbox.h>
// these \"forward declarations\" tell the compiler what other
// classes I WILL BE using without having to fully use
// the class declarations. The actual class declarations are included
// in the implementation file as <qlistbox> and <qlcdnumber>.
class QLCDNumber;
class QListBox;
class TicTacToe;
// This is the start of MY new class I am making called handmade
// It is based on QVBoz class
class HandMade : public QVBox
{
// Must have this Qt Keyword in order to use signals/slots/etc...
Q_OBJECT
public:
// This is the CONSTRUCTOR declaration
HandMade( QWidget *parent=0, char *name=0 );
QListBox *lb;
TicTacToe *kybd;
protected slots:
// These are SLOTS
void addNumber();
void removeNumber();
protected:
//These pointer values are used by the slots
QLCDNumber *lcd;
//QListBox *lb;
//Need to watch the keybopard
//TicTacToe *kybd;
};
#endif
***** tictactoe.h ********
#ifndef TICTACTOE_H
#define TICTACTOE_H
#include <qwidget.h>
class TicTacToe : public QWidget
{
Q_OBJECT
public:
TicTacToe(QWidget *parent = 0, const char *name = 0);
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
enum { Empty = \'-\', Cross = \'X\', Nought = \'O\' };
QRect cellRect(int row, int col) const;
int cellWidth() const { return width() / 3; }
int cellHeight() const { return height() / 3; }
char board[3][3];
};
#endif