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. QT: Adding files to list widget
QtWS25 Last Chance

QT: Adding files to list widget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 998 Views
  • 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.
  • A Offline
    A Offline
    Aashu10
    wrote on last edited by Aashu10
    #1

    I have a tool button and a listWidget(connected by 4 tab widgets). i want some files to appear on listwidget when tool button is clicked.

    connect(ui->toolButton, SIGNAL(clicked(bool)),this, SLOT() );
    

    Not sure what the slot is going to be. below is my code for selecting files.

    void MainWindow::Filemaking(int index)
    
        QStringList myFiles;
        QString myDir, myType;
        QListWidget *myWidget = new QListWidget;
        QString plat= ui->Platform_Combo->currentText();
        QString var= ui->Variant_Combo->currentText();
    
        if (index==0)
        {
            myDir.append("\\..\\1_CAN\\"+plat+"\\"+var);
            myType.append("*.can");
            myWidget = ui->listWidget_CAN;
        }
        else if (index==1)
        {
            myDir.append("\\..\\1_Triggers\\""+plat+"\\"+var);
            myType.append("*.tri");
            myWidget = ui->listWidget_TRI;
        }
        else if (index==2)
        {
            myDir.append("\\..\\3_Scripts\\""+plat+"\\"+var);
            myType.append("*.scr");
            myWidget = ui->listWidget_SCR;
        }
        else if (index==3)
        {
            myDir.append("\\..\\4_Calib\\""+plat+"\\"+var);
            myType.append("*.svl");
            myWidget = ui->listWidget_SVL;
        }
        else
        {
            myDir.append("");
            myType.append("*.*");
            myWidget->clear();
        }
        myWidget->clear();
        QString path=QDir::currentPath()+myDir+ui->Variant_Combo->currentText()+"\\";
        QDirIterator it(path, QStringList() << myType, QDir::Files);
        while (it.hasNext())
        {
            it.next();
            myFiles.append(it.fileName());
        }
        if (ui->UseCommons->isChecked())
        {
            path=QDir::currentPath()+myDir+"_common\\";
            QDirIterator it2(path, QStringList() << myType, QDir::Files, QDirIterator::Subdirectories);
            while (it2.hasNext())
            {
                it2.next();
                myFiles.append(it2.fileName());
            }
        }
        myWidget->addItems(myFiles);
    }
    

    Not sure how to assign this to tool button clicked. Not sure how to proceed ahead

    This is how my tab looks: http://imgur.com/gguuWBv

    RatzzR 1 Reply Last reply
    0
    • A Aashu10

      I have a tool button and a listWidget(connected by 4 tab widgets). i want some files to appear on listwidget when tool button is clicked.

      connect(ui->toolButton, SIGNAL(clicked(bool)),this, SLOT() );
      

      Not sure what the slot is going to be. below is my code for selecting files.

      void MainWindow::Filemaking(int index)
      
          QStringList myFiles;
          QString myDir, myType;
          QListWidget *myWidget = new QListWidget;
          QString plat= ui->Platform_Combo->currentText();
          QString var= ui->Variant_Combo->currentText();
      
          if (index==0)
          {
              myDir.append("\\..\\1_CAN\\"+plat+"\\"+var);
              myType.append("*.can");
              myWidget = ui->listWidget_CAN;
          }
          else if (index==1)
          {
              myDir.append("\\..\\1_Triggers\\""+plat+"\\"+var);
              myType.append("*.tri");
              myWidget = ui->listWidget_TRI;
          }
          else if (index==2)
          {
              myDir.append("\\..\\3_Scripts\\""+plat+"\\"+var);
              myType.append("*.scr");
              myWidget = ui->listWidget_SCR;
          }
          else if (index==3)
          {
              myDir.append("\\..\\4_Calib\\""+plat+"\\"+var);
              myType.append("*.svl");
              myWidget = ui->listWidget_SVL;
          }
          else
          {
              myDir.append("");
              myType.append("*.*");
              myWidget->clear();
          }
          myWidget->clear();
          QString path=QDir::currentPath()+myDir+ui->Variant_Combo->currentText()+"\\";
          QDirIterator it(path, QStringList() << myType, QDir::Files);
          while (it.hasNext())
          {
              it.next();
              myFiles.append(it.fileName());
          }
          if (ui->UseCommons->isChecked())
          {
              path=QDir::currentPath()+myDir+"_common\\";
              QDirIterator it2(path, QStringList() << myType, QDir::Files, QDirIterator::Subdirectories);
              while (it2.hasNext())
              {
                  it2.next();
                  myFiles.append(it2.fileName());
              }
          }
          myWidget->addItems(myFiles);
      }
      

      Not sure how to assign this to tool button clicked. Not sure how to proceed ahead

      This is how my tab looks: http://imgur.com/gguuWBv

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

      @Aashu10
      Check for the active tab and connect it to Filemaking .Then on a toolbutton clicked get file to display.

      --Alles ist gut.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Aashu10
        wrote on last edited by
        #3

        Solved! thanks @Ratzz

        RatzzR 1 Reply Last reply
        0
        • A Aashu10

          Solved! thanks @Ratzz

          RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by
          #4

          @Aashu10
          Once your problem is solved please use the Topic Tools button to mark as Solved.
          Thank you!

          --Alles ist gut.

          1 Reply Last reply
          1

          • Login

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