Search code examples
c++cqtfile-browser

How to browse folders in C++ or C?


I am implementing a program in C (also in C++) to sort files using threads, I need to implement a GUI in C++ or C to select the file to sort, without indicating the path through input standard (a equivalent of JFileChooser in Java). What tutorials do you recommend? I was reading about Qt but I'm not very familiar with this IDE. If you have any example would help me a lot.


Solution

  • Very simple with QT:

     void openFile()
      {
        QFileDialog::getOpenFileName( this, tr("Open Document"), QDir::currentPath(), tr("Document files (*.doc *.rtf);;All files (*.*)"), 0, QFileDialog::DontUseNativeDialog );
    
        QString filename = QFileDialog::getOpenFileName( 
            this, 
            tr("Open Document"), 
            QDir::currentPath(), 
            tr("Document files (*.doc *.rtf);;All files (*.*)") );
        if( !filename.isNull() )
        {
          qDebug( filename.toAscii() );
        }
      }