Qt qDebug: no print out

733 Views Asked by At

I've included 'qDebug.h' and iostream and stdio.h in my .cpp code and qDebug has been used correctly, but nothing happens in my Output window... I've tried qDebug and cout, wanna to print out all the data from the txt file on the print window but failed. Could anyone tell me how to make all those four columns of data be stored in four Qvectors as integers? Here I want to get the four groups of data to plot curves.

#include "dynamicplot.h"
#include "ui_dynamicplot.h"
#include "ui_confirmdialog.h"
#include "confirmdialog.h"
#include <QFile>
#include <QFileDialog>
#include <QMessageBox>
#include <QDebug>
#include <QFileInfo>
#include <QVector>
#include <stdio.h>
#include <iostream>
#include <qdebug.h>

using namespace std;
DynamicPlot::DynamicPlot(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DynamicPlot)
{
    ui->setupUi(this);
}

DynamicPlot::~DynamicPlot()
{
    delete ui;
}

void DynamicPlot::on_pB1_clicked()
{
    QString file_full,filePath;
    QFileInfo fi;
    file_full = QFileDialog::getOpenFileName(this, tr("选择文件"),tr( "*.txt"));
    fi=QFileInfo(file_full);
    //=fi.fileName();
    filePath=fi.absolutePath();

   if(!file_full.isNull()){
        QFile file(file_full);

        if(!file.open(QFile::ReadOnly|QFile::Text)){
           QMessageBox::warning(this,tr("Error"),tr("read file error:%1").arg(file.errorString()));
            return;
        }
        ui->textEdit_2->setPlainText(filePath);
        QTextStream in(&file);
        QApplication::setOverrideCursor(Qt::WaitCursor);
        dialog = new ConfirmDialog(this);
        dialog->setModal(false);
        dialog->ui->textEdit->setPlainText(in.readAll());
        QApplication::restoreOverrideCursor();
        dialog->show();
         //try QDebug
        while (!in.atEnd())
        {
         QString line = in.readLine();
         line = line + "\n";
         //data = data + line;
         qDebug()<<line.toStdString().data();
        }
        //try cout
        QVector<int>point_x;
        QVector<int>point_y;
            //int i=0,k=0;
            int i=0;
            while(!file.atEnd())
            {
                QString lineString_x=QString(file.readLine()).trimmed();
                //QString lineString_y=QString(file.readLine()).trimmed();
                point_x<<(int)(i++,lineString_x.toInt());
                //point_y<<(int)(k++,lineString_y.toInt());

            }
            for(i=0;i<point_x.count();i++)
            {
            //qDebug()<<point_x[i];
            //qDebug()<<point_y[i];
             cout<<point_x[i]<<endl;
            }

    }

    else{
        qDebug()<<"cancle";
    }

}

This is the print out window: this is the print out window

This is the UI: this is the ui

1

There are 1 best solutions below

2
On

Do you have

CONFIG += console

in your .pro? You have to rebuild your project.