In my application, QFileDialog is used QFileDialog - when choosing a playlist and mp3 file.

Recently, when calling QFileDialog::getOpenFileName() , a SIGSEGV error began to appear. However, if you call QFileDialog::getOpenFileName() in the MainWindow constructor, then all subsequent calls to this method do not give any errors.

MediaplayerCfg - the class in which the first QFileDialog call occurs

 class MediaplayerCfg : public QObject { Q_OBJECT public slots: void slot_setPosition(int value); 

mediaplayer.cpp (cited only a fragment of the function, since the rest of the work only works with the player)

 void MediaplayerCfg::slot_playTrack() { filename = QFileDialog::getOpenFileName(&wgt, tr("Открыть mp3 файл"), QDir::homePath(), tr("mp3 файлы (*.mp3)")); qDebug() << filename; // filename = "/home/timur/Downloads/Music/Concorde - Just Kiss Her.mp3"; player->setMedia(QUrl::fromLocalFile(filename) ); player->setVolume(50); 

Tracklist Functional - class to work with playlist
tracklist.h

 class TracklistFunctional : public QObject { Q_OBJECT public: ... void parsePlaylist(); }; 

tracklist.cpp

 // Здесь мы открываем плейлист и записываем пути к трекам в currentTracklist void TracklistFunctional::parsePlaylist() { QString filename = QFileDialog::getOpenFileName(wgt, tr("Открыть файл конфигурации"), QDir::homePath(), tr("mp3 файлы (*.mp3)")); QFile playList(filename); if (playList.open(QIODevice::ReadOnly) == false) { QMessageBox mesError; mesError.setText("\tERROR\n" "Playlist can't be open."); mesError.setStandardButtons(QMessageBox::Cancel); mesError.exec(); } currentTracklist.clear(); QTextStream parseStream(&filename); QString line; while(parseStream.atEnd() ) { line = parseStream.readLine(); currentTracklist.append(line); } playList.close(); } 
  • The code that you have is absolutely valid in the question, the problem is in your code. Locate the problem down to the line and attach the problem code - gil9red
  • I don't like &wgt , maybe that's the problem. Try passing NULL or nullptr instead. It will become: QString filename = QFileDialog::getOpenFileName(nullptr, tr("Открыть mp3 файл"), QDir::homePath(), tr("mp3 файлы (*.mp3)")); - gil9red
  • one
    Moreover, there in one place &wgt , and in another wgt . - vegorov
  • @ gil9red Unfortunately, it did not help - Recursive Daun
  • @vegorov This way I tried to somehow correct the error, but it did not help - Recursive Daun

1 answer 1

The problem was in putting a MediaplayerCfg class object into a new stream. Because of this, there was something like a struggle for resources (I don’t know exactly what was happening).