Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, December 2006
Problems Using QTextStream


Message 1 in thread

I want to have a global QTextStream object that I use to print debug 
information to.  It compiles fine, but if I ever try to use my 
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::Debug()
{
	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);
}

--
 [ signature omitted ] 

Message 2 in thread

Hi,

> Here's all the relevant code:

Could you show us the code that produces the error message? As far as I 
can understand this is the code that compiles, not the one that gives 
the error.

--
 [ signature omitted ] 

Message 3 in thread

Dimitri wrote:
> Hi,
> 
>> Here's all the relevant code:
> 
> Could you show us the code that produces the error message? As far as I 
> can understand this is the code that compiles, not the one that gives 
> the error.
> 
> -- 
> Dimitri

As I said, anytime the object QTextStream is used (the one named dout), 
the program gives that message.  So the simplest example would be:

#include "Debug.h"

int main()
{
	dout << "testing";
}

--
 [ signature omitted ] 

Message 4 in thread

Hi,

> As I said, anytime the object QTextStream is used (the one named dout), 
> the program gives that message.  So the simplest example would be:
> 
> #include "Debug.h"
> 
> int main()
> {
>     dout << "testing";
> }

What is "dout"? A QTextStream? If so, is it correct that the "Debug" 
class is irrelevant here?

--
 [ signature omitted ] 

Message 5 in thread

Hi,

> As I said, anytime the object QTextStream is used (the one named dout), 
> the program gives that message.  So the simplest example would be:
> 
> #include "Debug.h"
> 
> int main()
> {
>     dout << "testing";
> }

This works for me (on Linux with Qt 4.2.2). Which version of Qt on which 
platform are you running?

--
 [ signature omitted ]