Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3105591
  • 博文数量: 396
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4209
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-04 13:04
文章分类

全部博文(396)

文章存档

2022年(1)

2021年(2)

2020年(8)

2019年(24)

2018年(135)

2017年(158)

2016年(68)

我的朋友

分类: 嵌入式

2018-06-13 21:28:48

#include "mainWindows.h"

QString chakan(QString path){
  QDir dir(path);
  QString new_name;
  foreach(QFileInfo mfi ,dir.entryInfoList())
  {
    if(mfi.isFile())
    {
        new_name= mfi.fileName();
      //  qDebug()<< "File :" << mfi.fileName();

    }else
    {
        if(mfi.fileName()=="." || mfi.fileName() == "..")continue;
        qDebug() << "Entry Dir" << mfi.absoluteFilePath();
        chakan(mfi.absoluteFilePath());
    }
  }
    return new_name;
}

QString read_result_head(const char *file_name)
{
    QString line;
    QString displayString;
        QFile file(file_name);
         if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
         {
             qDebug()<<"Can't open the file!"<          }
             QTextStream stream(&file);
             // = in.readLine();
             stream.seek(0);
             while(!stream.atEnd())
             {
                 printf("a\n");
                 line = stream.readLine();
                 displayString.append(line);
               //  qDebug() << line;
                 break;
             }
                 file.close();   //关闭文件


    return displayString;
}
QString read_result_data(const char *file_name)
{
    QString line;
    QString displayString;
        QFile file(file_name);
         if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
         {
             qDebug()<<"Can't open the file!"<          }
             QTextStream stream(&file);
             // = in.readLine();
             stream.seek(0);
             while(!stream.atEnd())
             {
                 printf("a\n");
                 line = stream.readLine();
                 displayString.append(line);
               //  qDebug() << line;
               //  break;
             }
                 file.close();   //关闭文件


    return line;
}
MainWindow::MainWindow(QWidget *parent)

    : QMainWindow(parent)

{
    std::string str;
    char *path_name;
    path_name=(char *)malloc(100);

    char *str_data;
    str_data=(char *)malloc(100);
    //设置窗口大小

    this->resize(480,272);

    int r=0;
    const char *abc;

    QString temp;
    QString head_name;
    QTableView *table=new QTableView;

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    table->setFont(QFont("wenquanyi", 6, QFont::Bold));

    QVBoxLayout *pVBoxLayout = new QVBoxLayout(this);
    pVBoxLayout->addWidget(table);
    QStandardItemModel *model=new QStandardItemModel( 1, 13);

    table->resize(480,272);
    table->setColumnWidth(0, 85);
      QString test_name;
      test_name=chakan("/home/sinyd210/test/product_data");
      test_name="/home/sinyd210/test/product_data/"+test_name;

  //      test_name=chakan("/media/mmcblk0p1/test_log/");
  //      test_name="/media/mmcblk0p1/test_log/"+test_name;

      QByteArray product_result_name=test_name.toLatin1();
      path_name=product_result_name.data();
      qDebug()<< path_name;

      temp=read_result_head(path_name);
    for(int head=4;head<13;++head)
    {
        head_name=temp.section(',',head,head);
        QByteArray ba=head_name.toAscii();
        str_data=ba.data();
        qDebug() <<  str_data;
        abc =str_data;
        model->setHeaderData(head, Qt::Horizontal, QObject::tr(abc));
     }

  //  str = temp.toStdString();
  //

    temp=read_result_data(path_name);
    qDebug() << temp<     for(int row=0;row<10;++row)
    {
          for( r=0; r<13; ++r )
          {
           //   qDebug() << temp<
              QStandardItem *item = new QStandardItem( QString(temp.section(',',r,r)).arg(r+1) );
              model->setItem( row, r, item );
          }
     }
    table->verticalHeader()->setDefaultSectionSize(25);
    table->horizontalHeader()->setDefaultSectionSize(35);
    table->setModel(model); // 正常设置模型,没有任何特殊之处
    model->setHeaderData(0, Qt::Horizontal, QObject::tr("timestamp"));
    model->setHeaderData(1, Qt::Horizontal, QObject::tr("product_id"));
    model->setHeaderData(2, Qt::Horizontal, QObject::tr("duration"));
    model->setHeaderData(3, Qt::Horizontal, QObject::tr("illegal"));





    table->setStyleSheet("QTableView { border: none;"
                                     "selection-background-color: #8EDE21;"
                                     "color: black}");
   // BarDelegate delegate;
  //  table.setItemDelegateForColumn( 1, &delegate ); // 设置第一列为代理
  //   this->setCentralWidget(table);
    QColor(green);
    table->show();

}

MainWindow::~MainWindow()

{

}






































































阅读(9059) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~