The first output in the textedit is a number 3, I don't know why that number is coming form Qt::LogText. This question is based from a previous question I had asked, I'm using the same qdebugstream header file from the link below.
Redirect std::cout to a QTextEdit
The new project below is a QT Gui Application that will redirect the cout to a textedit. Also, since settextformat() is no longer a member of QTextEdit, I converted Qt::LogText into a string.
This was based on another post but I did not understand the solution. QTextEdit::setTextFormat(Qt::LogText) does not exist anymore, what else can I use to log?. Can someone provide more information on this?
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->textEdit->setReadOnly(true);
ui->textEdit->setText(QString("%1").arg(Qt::LogText));
QDebugStream qout(std::cout, ui->textEdit);
cout << "Send this to the Text Edit!" << endl;
}
MainWindow::~MainWindow()
{
delete ui;
}
Mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "qdebugstream.h"
#include "stdio.h"
#include "iostream"
using namespace std;
namespace Ui {
class MainWindow;
}
class QtextEdit;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H