View Full Version : Tried to redirect cout & cerr to QTextEdit instead of Console, but not working!
Krish
26th March 2008, 10:21
Hello! Friends,
I have designed a GUI in which i have lots of cout & cerr messages. Right now am able to see all those in console window but i want them to be displayed in my GUI's QTextEdit widget.
For this i made forum search and found this ("http://www.qtcentre.org/forum/f-qt-programming-2/t-console-replacement-6361.html/?highlight=qInstallMsgHandler" ) from where i got to know that i will have to make my own streaming class that inherits std::ostream and outputs everything using qDebug or some completely different mechanism. Also here i found that i can use qdebugstream.h header to do the needful, but its not working :( May be i might have made mistake in implementing it.
Here is what i tried: -
#include <QtGui>
#include <iostream>
#include "qdebugstream.h"
using namespace std;
#include "log.h"
mylog::mylog(QWidget *parent)
:QWidget( parent )
{
setupUi(this); // this sets up GUI
mylog::setWindowTitle(QString("Checking log"));
connect( Start, SIGNAL( clicked() ), this, SLOT( examine() ) );
}
void mylog::examine()
{
cout <<"Hello! We are ready for working" << endl;
QDebugStream cout(std::cout,logTextEdit);
QDebugStream cerr(std::cerr,logTextEdit);
}
Can anyone please let me know where am i making mistake. Or is there any other way to do the needful.
I will be grateful if helped--> Thanks in advance.:)
Stukfruit
26th March 2008, 13:26
You're setting the stream after sending the text to cout. You should do it the other way around: first, set the streams, then, start sending text to it.
Krish
26th March 2008, 14:31
Hello! Stukfruit,
Thanks for suggesting me that, but i have already tried that out by which i got following error's: -
void mylog::examine()
{
QDebugStream cout(std::cout,logTextEdit);
QDebugStream cerr(std::cerr,logTextEdit);
cout <<"Hello! We are ready for working" << endl;
}
#########error's#########
In file included from log.cpp:5:
qdebugstream.h: In member function `virtual std::streamsize QDebugStream::xsputn
(const char*, std::streamsize)':
qdebugstream.h:50: warning: comparison between signed and unsigned integer expre
ssions
qdebugstream.h:53: warning: comparison between signed and unsigned integer expre
ssions
In file included from log.cpp:5:
qdebugstream.h:74:7: warning: no newline at end of file
log.cpp: In member function `void mylog::examine()':
log.cpp:27: error: no match for 'operator<<' in 'cout << "Hello! We are ready fo
r working"'
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qchar.h:365: note: cand
idates are: QDataStream& operator<<(QDataStream&, const QChar&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qbytearray.h:534: note:
QDataStream& operator<<(QDataStream&, const QByteArray&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qstring.h:1008: note:
QDataStream& operator<<(QDataStream&, const QString&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/kernel/qobject.h:457: note:
QDebug operator<<(QDebug, const QObject*)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/io/qiodevice.h:244: note:
QDebug operator<<(QDebug, QFlags<QIODevice::OpenModeFlag>)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/io/qtextstream.h:286: note:
QTextStream& operator<<(QTextStream&, QTextStream&(*)(QTextStream
&))
../../../Qt/4.3.4/include/QtCore/../../src/corelib/io/qtextstream.h:289: note:
QTextStream& operator<<(QTextStream&, QTextStreamManipulator)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qregexp.h:141: note:
QDataStream& operator<<(QDataStream&, const QRegExp&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qstringlist.h:229: note
: QDataStream& operator<<(QDataStream&, const QStringList&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qlocale.h:579: note:
QDataStream& operator<<(QDataStream&, const QLocale&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/io/qurl.h:250: note:
QDataStream& operator<<(QDataStream&, const QUrl&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/io/qurl.h:255: note:
QDebug operator<<(QDebug, const QUrl&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/kernel/qvariant.h:590: note:
QDebug operator<<(QDebug, const QVariant&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/kernel/qvariant.h:496: note:
QDataStream& operator<<(QDataStream&, const QVariant&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/kernel/qvariant.h:498: note:
QDataStream& operator<<(QDataStream&, QVariant::Type)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/kernel/qvariant.h:591: note:
QDebug operator<<(QDebug, QVariant::Type)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qpoint.h:102: note:
QDataStream& operator<<(QDataStream&, const QPoint&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qpoint.h:182: note:
QDebug operator<<(QDebug, const QPoint&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qpoint.h:236: note:
QDataStream& operator<<(QDataStream&, const QPointF&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qpoint.h:357: note:
QDebug operator<<(QDebug, const QPointF&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qline.h:161: note:
QDebug operator<<(QDebug, const QLine&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qline.h:165: note:
QDataStream& operator<<(QDataStream&, const QLine&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qline.h:321: note:
QDebug operator<<(QDebug, const QLineF&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qline.h:325: note:
QDataStream& operator<<(QDataStream&, const QLineF&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qsize.h:101: note:
QDataStream& operator<<(QDataStream&, const QSize&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qsize.h:196: note:
QDebug operator<<(QDebug, const QSize&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qsize.h:252: note:
QDataStream& operator<<(QDataStream&, const QSizeF&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qsize.h:357: note:
QDebug operator<<(QDebug, const QSizeF&)
../../../Qt/4.3.4/include/QtCore/../../src/corelib/tools/qrect.h:198: note:
QDataStream& operator<<(QDataStream&, const QRect&)
........
..........
..............
...............This continues & finally ../..
../../../Qt/4.3.4/include/QtGui/../../src/gui/itemviews/qtreewidget.h:248: note:
QDataStream& operator<<(QDataStream&, const QTreeWidgetItem&)
../../../Qt/4.3.4/include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:910:
note: QDebug operator<<(QDebug, QGraphicsItem*)
../../../Qt/4.3.4/include/QtGui/../../src/gui/widgets/qsplitter.h:152: note:
QTextStream& operator<<(QTextStream&, const QSplitter&)
mingw32-make[1]: *** [release/log.o] Error 1
Please help me in solving the problem.:)
Thanks again.
danadam
26th March 2008, 23:36
QDebugStream cout(std::cout, textEdit);
QDebugStream cerr(std::cerr, textEdit);
cout <<"Hello! We are ready for working" << endl;
You are trying to write to QDebugStream and you should write to std::cout, so try this:
std::cout <<"Hello! We are ready for working" << std::endl;
instead.
Krish
27th March 2008, 10:21
Hello! danadam,
Thanks for taking out time & replying me. I had include the std namespace at the beginning of the implementation, but it wasn't working.
But now i tried to separately add std::cout its working.:)
Thanks again & Best Regards.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.