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. Mainwindow and Second window closes after saving QTableWidget contents in .csv file.
Forum Updated to NodeBB v4.3 + New Features

Mainwindow and Second window closes after saving QTableWidget contents in .csv file.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 256 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    Rututraj
    wrote on last edited by SGaist
    #1

    Hi all,
    This is my first question here, hope to get get answer soon.
    I have processed some data and displayed it on QTableWidget on second window.
    I used Qtetxstream and QFile to save this data in .csv file using pushbutton.
    But as soon as I click Pushbutton though the contents are saved, it closes both MainWindow and Second window and show message as The program has unexpectedly finished.

    Code snippet:
    void ErrorInfoTable::on_pushButton_Save_clicked()
    {
    QFile file(file path);

    if(!file.open(QFile::WriteOnly | QFile::Truncate))
    {
        QMessageBox::warning(this, "", "File not open");
    }
    

    for(int row = 0; row < NumberofErrors_ErrInfo; row++)
    {
    for(int col = 0; col < 6; col++)
    {
    QTextStream out(&file);
    QString text = ui->tableWidget->item(row, col)->text();
    out << text << ",";
    file.flush();
    if(col == 5)
    {
    out << "\n";
    }
    }

    }

    file.close();

    }

    Pl45m4P J.HilkJ 2 Replies Last reply
    0
    • R Rututraj

      Hi all,
      This is my first question here, hope to get get answer soon.
      I have processed some data and displayed it on QTableWidget on second window.
      I used Qtetxstream and QFile to save this data in .csv file using pushbutton.
      But as soon as I click Pushbutton though the contents are saved, it closes both MainWindow and Second window and show message as The program has unexpectedly finished.

      Code snippet:
      void ErrorInfoTable::on_pushButton_Save_clicked()
      {
      QFile file(file path);

      if(!file.open(QFile::WriteOnly | QFile::Truncate))
      {
          QMessageBox::warning(this, "", "File not open");
      }
      

      for(int row = 0; row < NumberofErrors_ErrInfo; row++)
      {
      for(int col = 0; col < 6; col++)
      {
      QTextStream out(&file);
      QString text = ui->tableWidget->item(row, col)->text();
      out << text << ",";
      file.flush();
      if(col == 5)
      {
      out << "\n";
      }
      }

      }

      file.close();

      }

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @Rututraj

      Debug and try to find the line where exactly the crash happens


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • R Rututraj

        Hi all,
        This is my first question here, hope to get get answer soon.
        I have processed some data and displayed it on QTableWidget on second window.
        I used Qtetxstream and QFile to save this data in .csv file using pushbutton.
        But as soon as I click Pushbutton though the contents are saved, it closes both MainWindow and Second window and show message as The program has unexpectedly finished.

        Code snippet:
        void ErrorInfoTable::on_pushButton_Save_clicked()
        {
        QFile file(file path);

        if(!file.open(QFile::WriteOnly | QFile::Truncate))
        {
            QMessageBox::warning(this, "", "File not open");
        }
        

        for(int row = 0; row < NumberofErrors_ErrInfo; row++)
        {
        for(int col = 0; col < 6; col++)
        {
        QTextStream out(&file);
        QString text = ui->tableWidget->item(row, col)->text();
        out << text << ",";
        file.flush();
        if(col == 5)
        {
        out << "\n";
        }
        }

        }

        file.close();

        }

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        hi @Rututraj
        said in Mainwindow and Second window closes after saving QTableWidget contents in .csv file.:

        QString text = ui->tableWidget->item(row, col)->text();

        best guess is, either row or col is to large, for the tableWidget index


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        R 1 Reply Last reply
        3
        • J.HilkJ J.Hilk

          hi @Rututraj
          said in Mainwindow and Second window closes after saving QTableWidget contents in .csv file.:

          QString text = ui->tableWidget->item(row, col)->text();

          best guess is, either row or col is to large, for the tableWidget index

          R Offline
          R Offline
          Rututraj
          wrote on last edited by
          #4

          @J-Hilk
          Yes row index was getting out of range,
          Thanks :)

          1 Reply Last reply
          0

          • Login

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