Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to display the output of the program mentioned below using a textBrowser ?

    General and Desktop
    2
    2
    300
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Jayashri last edited by

      This program displays the output in a message box but instead I want it in a TextBrowser...

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QTextStream>
      #include <QMessageBox>
      #include <QFileDialog>
      #include <QDebug>
      #include "dia.h"
      #include"dai2.h"

      MainWindow::MainWindow(QWidget* parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow) {
      ui->setupUi(this);
      }

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

      #include <QFile>

      void CompareRule1(int cline,QString OnePara ) {

      // check the rules
      if (OnePara.contains("//"))
      QMessageBox::warning(NULL, "My Application", QString("line %1 -ERROR.\nRule 1 Violated !").arg(cline) );

      }
      void CompareRule2(int cline,QString OnePara ) {

      // check the rules
      if (OnePara.contains("hai"))
      QMessageBox::warning(NULL, "My Application", QString("line %1 -ERROR.\nRule 2 Violated !").arg(cline) );

      }

      void MainWindow::on_pushButton_clicked()
      {
      QString fileName = QFileDialog::getOpenFileName(this, tr("Opentext File"),
      QDir::currentPath(),
      tr("text Files (*.txt)"));
      if (fileName.isEmpty()) {
      return;
      }
      else
      {
      dia d;
      d.setModal(false);
      d.exec();

      }
      QFile inputFile(fileName);
      QString Para;
      int lineCount = 0;
      if (inputFile.open(QIODevice::ReadOnly)) {
        QTextStream in(&inputFile);
        while (!in.atEnd())
        {
             lineCount++;
          QString line = in.readLine();
          qDebug() << lineCount << line;
          Para += line;
          qDebug()<<line;
          qDebug()<<Para;
          if (line!=NULL) { // we found blank line, so test and clear
                   (CompareRule1(lineCount,line));
                    (CompareRule2(lineCount,line));
      
      
      
                              qDebug() << "ParaRead: " << Para;
            Para = ""; //clear
      
        }
        }
        inputFile.close();
      }
      

      }

      1 Reply Last reply Reply Quote 0
      • the_
        the_ last edited by

        Hi

        You can write the messages you display with QMessageBox into a QTextDocument and display this QTextDocument with QTextBrowser

        QTextBrowser *browser = new QTextBrowser;
        //...
        browser->setDocument(new QTextDocument("<your message here>");
        

        -- No support in PM --

        1 Reply Last reply Reply Quote 1
        • First post
          Last post