Privacy policyContactsAbout siteOpinionsGitHubDonate
© EVILEG 2015-2018
Recommend hosting

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

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
Feb. 18, 2019, 3:39 p.m.

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

  • Result:73points,
  • Rating points1
Feb. 15, 2019, 1:03 p.m.
Николай Булахтин

C++ - Test 002. Constants

  • Result:25points,
  • Rating points-10
Last comments
Feb. 14, 2019, 6:41 p.m.

Спасибо огромное! Заработало!
Feb. 12, 2019, 9:26 a.m.

Сам разборался, спасибо.
Feb. 12, 2019, 8:19 a.m.

День добрый! Можешь выложить форму mainwindow.ui от урока? Заранее спасибо
Feb. 11, 2019, 10:51 a.m.
Евгений Легоцкой

Нет, у меня проблема с жёстким диском случилась, занимался восстановлением ПК, ещё пару вечеров придётся этим заниматься, увы.
Now discuss on the forum
Feb. 17, 2019, 5:28 p.m.
Евгений Легоцкой

Добрый день. Очень извиняюсь за долгий ответ Первое, что нашёл, так это необходимость перерисовать чекбокс. void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem ...
Feb. 15, 2019, 3:36 p.m.
Евгений Легоцкой

Ну я тут нашёл одно решение, но сам его не проверял. Вам нужно помещать фамилии скорее всего в ячейки заголовка, и потом просто перерисовывать их QHeaderView * header = m_ui->tableWidget...
Feb. 15, 2019, 7:53 a.m.
Евгений Легоцкой

Добрый день! Не работал с remoteobjects, поэтому глянул документацию, чтобы рассмотреть, что это за зверь. После просмотра документации сложилось стойкой впечатление, что это вполне возм...
Feb. 14, 2019, 6:28 p.m.

Нашел решение на Java. Удалось интегрировать в проект сервиса на Qt, теперь из Qt запускаю Java-код акселерометра.
Join us in social networks

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