C
Chris Portka
I have a problem I've been working on for days now with global variable
use. I'm currently using QT for development but this same problem
should apply to anytime a C++ object is trying to be used globally.
Just assume the QT stuff is fine and that they are predefined library
objects. Anyway, I want to have a global QTextStream object that I use
to print debug information to. This program compiles fine, but if I
ever try to use my global QTextStream object it gives me the error:
"binary '<<' : no operator found which takes a left-hand operand of
type 'QTextStream'"
Any suggestions would be much appreciated. Thanks,
Chris
Here's all the relevant code:
DEBUG.H:
#ifndef DEBUG_H
#define DEBUG_H
#include <QMainWindow>
#include <QLabel>
#include <QTextStream>
#include <QSTring>
#include <QBuffer>
static QTextStream debugout;
class Debug : public QMainWindow
{
Q_OBJECT
public:
QLabel debugLabel;
QByteArray debugArray;
QBuffer debugBuffer;
Debug();
private:
private slots:
void textWritten(int numBytes);
};
#endif
DEBUG.CPP:
#include "Debug.h"
Debug:ebug()
{
setCentralWidget(&debugLabel);
debugout.setDevice(&debugBuffer);
connect(&debugBuffer, SIGNAL(bytesWritten(int)), this,
SLOT(textWritten(int)));
}
void Debug::textWritten(int numBytes)
{
QByteArray newText = debugBuffer.readAll();
debugArray.append(newText);
debugLabel.setText(debugArray);
}
use. I'm currently using QT for development but this same problem
should apply to anytime a C++ object is trying to be used globally.
Just assume the QT stuff is fine and that they are predefined library
objects. Anyway, I want to have a global QTextStream object that I use
to print debug information to. This program compiles fine, but if I
ever try to use my global QTextStream object it gives me the error:
"binary '<<' : no operator found which takes a left-hand operand of
type 'QTextStream'"
Any suggestions would be much appreciated. Thanks,
Chris
Here's all the relevant code:
DEBUG.H:
#ifndef DEBUG_H
#define DEBUG_H
#include <QMainWindow>
#include <QLabel>
#include <QTextStream>
#include <QSTring>
#include <QBuffer>
static QTextStream debugout;
class Debug : public QMainWindow
{
Q_OBJECT
public:
QLabel debugLabel;
QByteArray debugArray;
QBuffer debugBuffer;
Debug();
private:
private slots:
void textWritten(int numBytes);
};
#endif
DEBUG.CPP:
#include "Debug.h"
Debug:ebug()
{
setCentralWidget(&debugLabel);
debugout.setDevice(&debugBuffer);
connect(&debugBuffer, SIGNAL(bytesWritten(int)), this,
SLOT(textWritten(int)));
}
void Debug::textWritten(int numBytes)
{
QByteArray newText = debugBuffer.readAll();
debugArray.append(newText);
debugLabel.setText(debugArray);
}