QT: Adding files to list widget



  • 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



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



  • Solved! thanks @Ratzz



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.