0

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

TrebledJ
  • 8,713
  • 7
  • 26
  • 48
Lee Dennis
  • 57
  • 6
  • 1
    Hi there, by _print window_ do you mean _application output_? Also it seems like you have two separate questions? **Edit:** have you tried a simple `qDebug() << "hello world";` at the start of `void DynamicPlot::on_pB1_clicked()`? does output show when you click the button? – TrebledJ Nov 28 '18 at 05:15
  • Many thanks. Yeah what I mean is the application output. I add a simple qDebug()<<''Hello''at the start of the button clicked()part as what you say, and the output show. – Lee Dennis Nov 28 '18 at 05:39
  • But I wonder why it doesn't work below. – Lee Dennis Nov 28 '18 at 05:39
  • I'm guessing your call to `in.readAll()` will empty out the contents of `in`. So your while-loop `while (!in.atEnd())` won't run. I could be wrong though. Check that `in` is what you expect it to be. – TrebledJ Nov 28 '18 at 06:04
  • Thanks! You are right. – Lee Dennis Nov 29 '18 at 12:42

1 Answers1

1

Do you have

CONFIG += console

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

sassi67
  • 77
  • 1
  • 4