Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Portuguese
  4. Preencher um Table Widget com dados de um .txt [RESOLVIDO]
Forum Updated to NodeBB v4.3 + New Features

Preencher um Table Widget com dados de um .txt [RESOLVIDO]

Scheduled Pinned Locked Moved Portuguese
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.
  • L Offline
    L Offline
    lima_will
    wrote on last edited by
    #1

    Pessoal,

    Estou tentando preencher uma tabela com um arquivo .txt, o arquivo txt está com o seguinte formato:

    @192.168.0.1 executado OK
    192.168.0.2 erro Sem Acesso
    192.168.0.3 executado OK
    192.168.0.4 executado OK
    192.168.0.5 executado OK
    192.168.0.6 executado OK
    192.168.0.7 executado OK
    192.168.0.8 executado OK
    192.168.0.9 executado OK
    192.168.0.10 executado OK
    192.168.0.11 executado OK
    192.168.0.12 erro Sem Acesso
    192.168.0.13 erro Não Responde na Rede
    192.168.0.14 executado OK
    192.168.0.15 executado OK @

    Sei que preciso abri o arquivo e ler o mesmo e usar o espaço (" ") para separar cada string só que não consigo separar os
    dados e depois colocar cada um em uma célula individual.
    Meu código atual:

    @QFile inputFile("C:\log_instalador.txt");
    if(inputFile.open(QIODevice::ReadOnly))
    {
    QTextStream in (&inputFile);
    while (!in.atEnd()){
    QString line = in.readLine();
    QStringList fields = line.split(" ");
    //ui->tableWidget->setItem(coluna,0,new QTableWidgetItem(nome));
    ui->tableWidget->setItem(coluna,0,new QTableWidgetItem(fields));
    ui->tableWidget->setItem(coluna,1,new QTableWidgetItem(fields));
    coluna += 1;

        }
    }@
    

    O erro que recebo:

    @error: C2664: 'QTableWidgetItem::QTableWidgetItem(int)' : cannot convert parameter 1 from 'QStringList' to 'int'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called@

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TioRoy
      wrote on last edited by
      #2

      Você está fazendo errado.

      O fields é um QStringList. E o QTableWidgetItem aceita um QString como parâmetro.

      @
      QFile inputFile("C:\log_instalador.txt");
      if(inputFile.open(QIODevice::ReadOnly))
      {
      QTextStream in (&inputFile);
      while (!in.atEnd()){
      QString line = in.readLine();
      QStringList fields = line.split(" ");
      //ui->tableWidget->setItem(coluna,0,new QTableWidgetItem(nome));
      ui->tableWidget->setItem(coluna,0,new QTableWidgetItem(fields.at(0)));
      ui->tableWidget->setItem(coluna,1,new QTableWidgetItem(fields.at(1)));
      coluna += 1;

          }
      }
      

      @

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lima_will
        wrote on last edited by
        #3

        E TioRoy,

        Vou ter que pagar um caminhão de Coca-Cola para vc! Valeu mesmo!!
        Faltou os fields!
        Valeu mesmo!!

        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