I have registered a custom URI-Scheme for my Qt downloader app on Windows. The app works fine, and does exactly what I need it to do. The only problem is that each time I click on a new URL with the specified format, it opens a new instance of the app instead of adding the new item to the previously opened app. How can I avoid this problem? Do I need to check for the already opened apps each time I'm opening a new one? Is there a Qt way for doing this?
Here is the part of the code that handles adding the new file to the app.
if (event->type() == QEvent::FileOpen){
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
if (!fileEvent->url().isEmpty()){
addFilesToApp(fileEvent->url().toString(), argument_list);
}
}
UPDATE I found this post, and it helped me to solve the problem of opening multiple instances of the app by adding this four line between QAplication and MainWindow:
QApplication app(argc, argv);
QSharedMemory shared("75d3863a-1e79-43d5-97a3-ea7ffd67d02a");
if( !shared.create( 512, QSharedMemory::ReadWrite) ){
exit(0);
}
MainWindow window;
but now the app doesn't add new file to the download list when I click on one. I think it's because the addFilesToApp() function triggers by FileOpen Event.