G2A Many GEOs
SHARE
TWEET

Untitled

a guest Jan 19th, 2014 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.h"
  4.  
  5.  
  6. #include <QDebug>
  7. #include <QStandardItemModel>
  8.  
  9. #include <QStandardItem>
  10. #include <QStringListModel>
  11.  
  12.  
  13. #include <QAbstractItemModel>
  14. #include <QListView>
  15. #include <QVariant>
  16. #include "model.h"
  17. #include <cstdlib>
  18. #include <stdlib.h>
  19.  
  20. MainWindow::MainWindow(QWidget *parent) :
  21.     QMainWindow(parent),
  22.     ui(new Ui::MainWindow)
  23. {
  24.     ui->setupUi(this);
  25.  
  26.     testCmdAlternative();
  27. }
  28.  
  29. MainWindow::~MainWindow()
  30. {
  31.     delete ui;
  32. }
  33.  
  34.  
  35.  
  36. int MainWindow::testCmdAlternative() {
  37.  
  38.     FILE *in;
  39.     char buff[512];
  40.  
  41.     if(!(in = popen("export", "r"))){
  42.         return 1;
  43.     }
  44.  
  45.  
  46. //   TableModel *model = new TableModel(4, 2, this);
  47.  
  48. //    ui->tableView->setModel(model);
  49.  
  50. //    ui->tableView->horizontalHeader()->setModel(model);
  51.  
  52. //    for (int row = 0; row < 4; ++row) {
  53. //        for (int column = 0; column < 2; ++column) {
  54. //            QModelIndex index = model->index(row, column, QModelIndex());
  55. //            model->setData(index, QVariant(QString("(%1, %2)").arg(row).arg(column)));
  56. //        }
  57. //    }
  58.  
  59.  
  60.     QStringList envVarNames;
  61.     QStringList envVarPaths;
  62.  
  63.     int row = 1;
  64.  
  65.     while(fgets(buff, sizeof(buff), in)!=NULL){
  66.  
  67.         // cout << buff << "TEST " << endl;
  68.         string envPathVar = buff;
  69.  
  70.         //        string envPathVar = cmdResultList.at(i).toLocal8Bit().data();
  71.         //        // Convert to QString variable
  72.         QString envPathVarQ = QString::fromStdString(envPathVar);
  73.  
  74.         //        // Split PATH=/path/to/lib at the = to get varName and varPath(s)
  75.         QStringList nameSplitPath = envPathVarQ.split("=");
  76.  
  77.         qDebug() << "AT0" << nameSplitPath.at(0).toLocal8Bit().data();
  78.         qDebug() << "AT0" << nameSplitPath.at(1).toLocal8Bit().data();
  79.  
  80.         //        // Add EnvPath name to list
  81.         string envVarNameString = nameSplitPath.at(0).toLocal8Bit().data();
  82.         QString envVarName = QString::fromStdString(envVarNameString);
  83.         envVarNames.append(envVarName);
  84.  
  85.         //        // Add EnvPath path to list
  86.         string envVarPathString = nameSplitPath.at(1).toAscii().data();
  87.         QString envVarPath = QString::fromStdString(envVarPathString);
  88.         envVarPaths.append(envVarPath);
  89.  
  90.  
  91.  
  92.         /********************8 Add Path name to list*****************/
  93.         QString itemText = envVarName.replace("export",  "");
  94.         QListWidgetItem *newItem = new QListWidgetItem;
  95.         newItem->setText(itemText);
  96.  
  97.         ui->pathNameListWidget->insertItem(row, newItem);
  98.         row++;
  99.  
  100.     }
  101.     pclose(in);
  102.  
  103.     return 0;
  104. }
  105.  
  106.  
  107. void MainWindow::on_pathNameListWidget_currentRowChanged(int currentRow)
  108. {
  109.     QString currentVal = (ui->pathNameListWidget->currentIndex().data().toString());
  110.  
  111.     currentVal.trimmed();
  112.     currentVal.remove(" ");
  113.     // Convert QString to const char*
  114.     QByteArray currentValByteArray = currentVal.toUtf8();
  115.     const char *envVariable = currentValByteArray.data();
  116.  
  117.  
  118.     const char *getEnvPaths = getenv(envVariable);
  119.  
  120.     qDebug() << "char " <<  strlen(envVariable);
  121.     qDebug() << getEnvPaths;
  122.  
  123.     if(getEnvPaths == NULL){
  124.         qDebug() << "getenv is null";
  125.     }
  126.     // Set table model
  127.     TableModel *tableModel = new TableModel(5, 1, this);
  128.     ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
  129.     ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
  130.     ui->tableView->setEditTriggers(QAbstractItemView::DoubleClicked);
  131.  
  132.     int row = 0;
  133.  
  134.     QModelIndex index = tableModel->index(row, 0, QModelIndex());
  135.     // Set table column data
  136.     tableModel->setData(index, getEnvPaths, Qt::ItemIsEditable);
  137.  
  138.     ui->tableView->setModel(tableModel);
  139.  
  140. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top