Using JumpList to store files opened in the application when using Qt

winExtras, jumpList

JumpList, one of the features that are present only in Windows (version 7 and above). In this sheet, in particular, you can store links to the most recently opened files in the application.

To use this function, you need to

1. Connect the module

QT += winextras

2. Connect library

#include <QtWinExtras>

3. Make the appropriate JumpList section active

QWinJumpList jumplist;

4. Associate all the required file extensions with our application using the function

static void associateFileTypes(const QStringList &fileTypes)
    QString displayName = QGuiApplication::applicationDisplayName();
    QString filePath = QCoreApplication::applicationFilePath();
    QString fileName = QFileInfo(filePath).fileName();
    QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\Applications\\" + fileName, QSettings::NativeFormat);
    settings.setValue("FriendlyAppName", displayName);
    foreach (const QString& fileType, fileTypes)
        settings.setValue(fileType, QString());
    settings.setValue("FriendlyAppName", displayName);
    settings.setValue(".", QChar('"') + QDir::toNativeSeparators(filePath) + QString("\" \"%1\""));

Which is convenient to use in the main

QApplication a(argc, argv);
a.setApplicationDisplayName("QtWinExtras Test");

Now when you open a new file, a link to it will be added to the last JumpList section.

When clicking on one of the links that appears, our application will start with the file name as the second parameter (argv [1]). With such a configuration, it is reasonable to modify the main function so that the selected file is opened.

if(argc == 2)[1]).replace(QString("\\"),QString("/")));

It is also possible to implement when, when the application is started, it is checked if there is a copy of it running. If such a copy is found, the application will send the name of the selected file to it and finish its work. I wrote the following implementation, where the name of the file is written to the registry.

    HANDLE hCorvetEvent = CreateEventA(NULL, FALSE, FALSE, ("winExJumpList"));
    if (GetLastError() ==  ERROR_ALREADY_EXISTS)
        if(argc == 2)
            QSettings *settings;
            settings = new QSettings("Company", "my programm");
            settings->setValue("AddFile", QString::fromLocal8Bit(argv[1]).replace(QString("\\"),QString("/") ) ); 
        return 0;

The program uses a timer-based function to monitor the registry change and open the added file.

connect(ui->pushButton, &QPushButton::clicked, this, &MainWindow::openFile);
    QTimer *openFile = new QTimer;
    connect(openFile, &QTimer::timeout, this, &MainWindow::nextFile);
void MainWindow::nextFile()
    QSettings *settings;
    settings = new QSettings("Company", "my programm");
    QString s = settings->value("AddFile").toString();
        settings->setValue("AddFile", "");

Naturally, you will see the work of the program after you add the libraries necessary for the snack to the compiled exe-file.

Project with source code of the program

10% refund of hotel reservation amount on Booking
10% refund of hotel reservation amount on Booking
We offer a link with a 10% return on the amount of the order when booking a hotel through Booking
This is a nice start to learning how to use QWinJumplist but the demo files do not work when I try to load a file from the jump list Windows can't find the location of the file.

Unless I right click on the Recent items and select to open the txt file through a second context menu as opposed to a straight double click of the item.


Only authorized users can post comments.
Please, Log in or Sign up
Looking for a Job?
14,000.00 руб. - 40,000.00 руб.
Разработчик Qt
Annino, Moscow Oblast, Russia
5,000.00 руб. - 15,000.00 руб.
Moskovskiy, Moscow, Russia
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

Aug. 22, 2019, 11:24 p.m.

Qt - Test 001. Signals and slots

  • Result:47points,
  • Rating points-6
Aug. 21, 2019, 10:23 a.m.
Andrej Ermoshin

C++ - Test 002. Constants

  • Result:58points,
  • Rating points-2
Aug. 21, 2019, 10:15 a.m.
Andrej Ermoshin

C++ - Test 001. The first program and data types

  • Result:86points,
  • Rating points6
Last comments
Aug. 19, 2019, 7:41 a.m.
Andrej Jankovich

это проблема дистрибутива, попробуйте установить через пакетный менеджер snap Суть проблемы: libQt5Core которая лежит в дистрибутиве требует версию glibc >= 2.25 у вас видимо …
Aug. 18, 2019, 6:09 a.m.

cqtdeployer /home/aleks/CQtDeployer/bin/cqtdeployer: /lib/x86_64-linux-gnu/ version `GLIBC_2.25' not found (required by /home/aleks/CQtDeployer/lib/ linux mint …
Aug. 17, 2019, 9:04 a.m.

github ChekableTView Правой групповая смена значения при перетаскивании левой как обычно.
Aug. 16, 2019, 1:03 p.m.
Evgenij Legotskoj

Потому, что в минуте 60 секунд
Aug. 16, 2019, 12:16 p.m.

а почему делитель 60000, а не 1000?
Now discuss on the forum
Aug. 24, 2019, 7:21 a.m.
Evgenij Legotskoj

Не помню, давно уже с QML не работал, по-моему, обычно пишет в консоль, что не находит файл. В любом случае какую-то ошибку в консоль выкидывает. Но если честно, если у вас проект будет ак…
Aug. 24, 2019, 4:27 a.m.
Brjus Gliff

Спасибо, вначале в документации было не понятно что к чему, теперь разобрался
Aug. 21, 2019, 8:36 a.m.

Александр, мне не нужно перебирать. Вы говорите правильно, сначала я написал избыточный код просто не подумав. Задача такая, мне нужно просто переложить из QMap в атрибуты xml тега все, что там …
Aug. 21, 2019, 3:16 a.m.

Если Вы разрабатываете какую-то универсальную утилиту, которая вообще не привязана к логике, тогда как вариант: 1. Получить список таблиц через QSqlDatabase::tables 2. Для каждой табли…
© EVILEG 2015-2019
Recommend hosting TIMEWEB