Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to display the output of the program mentioned below using a textBrowser ?

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 377 Views
  • 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 Offline
    J Offline
    Jayashri
    wrote on last edited by
    #1

    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
    0
    • the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      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
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved