Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding a QDialog to a QML Application?
Qt 6.11 is out! See what's new in the release blog

Adding a QDialog to a QML Application?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EStudley
    wrote on last edited by
    #1

    So using Qt 5.2 I created a Qt Quick Application project, which comes with qtquick2applicationviewer .h and .cpp, a main.cpp, and QML files.

    I want to add a .cpp and .h file to control system notifications based on things that happen in the main QML application. I was following the example here http://doc.qt.digia.com/4.6/desktop-systray.html but that is a QWidget in itself, not a QML view. I thought I could just create a C++ class that extends QDialog that i could call to display system notifications, but it seems it just doesn't work that way?

    Here's my current code:

    @#ifndef NOTIFICATIONS_H
    #define NOTIFICATIONS_H

    #include <QtGui>
    #include <QSystemTrayIcon>
    #include <QObject>
    #include <QString>
    #include <QDialog>

    class notifications : public QDialog
    {
    Q_OBJECT

    public:
    explicit notifications();
    ~notifications();

    private:
    QAction *quitAction;
    QSystemTrayIcon *trayIcon;
    QMenu *trayIconMenu;
    void createActions();
    void createTrayIcon();
    void createTrayIconMenu();
    };

    #endif // NOTIFICATIONS_H@

    @#include "notifications.h"
    #include <QSystemTrayIcon>
    #include <QDialog>
    #include <QMenu>

    notifications::notifications()
    {
    createActions();
    createTrayIcon();
    createTrayIconMenu();
    }

    notifications::~notifications()
    {
    }

    void notifications::createActions()
    {
    quitAction = new QAction("&Quit", this);
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
    }

    void notifications::createTrayIcon()
    {
    trayIconMenu = new QMenu(this);
    trayIconMenu->addAction(quitAction);
    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setContextMenu(trayIconMenu);
    }@

    Now all Qt Creator says is "QWidget: Cannot create a QWidget without QApplication." Does that mean I have to implement my entire QML application as a QApplication in Qt instead?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved