Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Persian
  4. خواندن و نوشت در tableView
Forum Updated to NodeBB v4.3 + New Features

خواندن و نوشت در tableView

Scheduled Pinned Locked Moved Persian
3 Posts 2 Posters 1.8k 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.
  • M Offline
    M Offline
    mehrzad
    wrote on last edited by
    #1

    با سلام
    اگه ممکن هست دوستان در مورد نوشتن محتویات یک
    tableView
    درفایل و خواندن ان راهنمایی بفرمایند ممنون میشم

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shs_night
      wrote on last edited by
      #2

      p{direction:rtl; text-align:right}. سلام
      راه های مختلفی برای این کار وجود داره. مثلا کدهای زیر محتویات Table View رو به فرمت html ذخیره میکنه

      @void saveTableView2Html()
      {
      const QString htmlFileName = QFileDialog::getSaveFileName(...);
      if( htmlFileName.isEmpty() ) // کاربر کنسل کرده است
      return;

      QFile file(htmlFileName);
      if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
          //خطایی رخ داده است
          return ;
      }
      
      QTextStream out(&file);
      out.setCodec("UTF-8");
      
      const int rowCount    = tableView->model()->rowCount();
      const int columnCount = tableView->model()->columnCount();
      
      out <<  "&lt;html&gt;\n"
              "&lt;head&gt;\n"
              "&lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"&gt;\n"
           <<  QString("&lt;title&gt;%1&lt;/title&gt;\n").arg(QFileInfo(file.fileName()).fileName())
            <<  "&lt;/head&gt;\n"
                "&lt;body dir=\"rtl\" bgcolor=#ffffff link=#5000A0&gt;\n"
                "<font face=\"Tahoma, Geneva, sans-serif\">\n"
                "<table border=1 cellspacing=0 cellpadding=10>\n";
      
      // جدول (header) هدر
      out << "<tr bgcolor=#f0f0f0>";
      for (int column = 0; column < columnCount; column++)
          if (!tableView->isColumnHidden(column))
              out << QString("<th>%1</th>").arg(tableView->model()->headerData(column, Qt::Horizontal).toString());
      out << "</tr>\n";
      file.flush();
      
      // داده های جدول
      for (int row = 0; row < rowCount; row++) {
          out << "<tr>";
          for (int column = 0; column < columnCount; column++) {
              if (!tableView->isColumnHidden(column)) {
                  QString data = tableView->model()->data(
                              tableView->model()->index(row, column)).toString() ;
      
                  out << QString("<td bkcolor=0>%1</td>").arg((!data.isEmpty()) ? data : QString("&nbsp;"));
              }
          }
          out << "</tr>\n";
      }
      out <<  "</table>\n"
              "</font>"
              "&lt;/body&gt;\n"
              "&lt;/html&gt;\n";
      file.close();
      
      qApp->beep();
      QDesktopServices::openUrl(QUrl("file:///" + htmlFileName
                                     ,QUrl::TolerantMode));
      

      }
      @

      QtSDK 1.2 + MinGW + Desktop !

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shs_night
        wrote on last edited by
        #3

        p{direction:rtl; text-align:right}. بیشتر به این قسمت توجه کن:
        @
        for (int row = 0; row < rowCount; row++) {
        for (int column = 0; column < columnCount; column++) {
        if (!tableView->isColumnHidden(column)) {
        QString data = tableView->model()->data(
        tableView->model()->index(row, column)).toString() ;@

        QtSDK 1.2 + MinGW + Desktop !

        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