Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Displaying QT widgets in QML
Forum Update on Monday, May 27th 2025

Displaying QT widgets in QML

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 4.5k Views
  • 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.
  • O Offline
    O Offline
    outdoor_guy
    wrote on 7 Mar 2011, 13:57 last edited by
    #1

    Hi

    I have the problem to have some old QT-widget-style applications, which should be wrapped by QML.
    Currently the old Main-Class I have to call is the following:
    @
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);@

    I registered that one the following way

    @qmlRegisterType<MainWindow>("Umbenennung",1,0,"Umbenennen");@

    The I made a QML-File in the following way

    @import Qt 4.7
    import Umbenennung 1.0

    Umbenennen
    {

    }@

    When I call this one, the old HMI is displayed

    However, if I start to do something like this:
    @import Qt 4.7
    import Umbenennung 1.0

    Item
    {
    id: tester

    Umbenennen
    {
    
    }
    

    }

    @

    the program crashes. The constructor of MainWindow was allready finished.

    Is there a way to wrap such kind of code inside QML without making changes on the old code?
    Or is there an other way to call such programs?

    This was the callstack of the crash:
    @0 QWidgetPrivate::invalidateGraphicsEffectsRecursively() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1075b66
    1 QWidgetPrivate::setDirtyOpaqueRegion() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1075be4
    2 QWidgetPrivate::updateIsOpaque() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x107d025
    3 QWidgetPrivate::setPalette_helper(QPalette const&) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x107d659
    4 QWidgetPrivate::resolvePalette() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x107d6ea
    5 QWidgetPrivate::propagatePaletteChange() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x107d4e3
    6 QWidgetPrivate::setPalette_helper(QPalette const&) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x107d651
    7 QWidgetPrivate::resolvePalette() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x107d6ea
    8 QWidget::event(QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x108250f
    9 QMenuBar::event(QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x14fba5f
    10 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1023c6c
    11 QApplication::notify(QObject*, QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1029669
    12 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c4fc5b
    13 QWidget::ensurePolished() const /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x10778cb
    14 QWidget::ensurePolished() const /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1077911
    15 QWidget::event(QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1082128
    16 QMainWindow::event(QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x14c46d7
    17 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1023c6c
    18 QApplication::notify(QObject*, QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1029669
    19 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c4fc5b
    20 QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c52f1c
    21 QCoreApplication::sendPostedEvents(QObject*, int) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c5307d
    22 ?? /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c7e964
    23 g_main_context_dispatch /lib/libglib-2.0.so.0 0 0x22d85e5
    24 ?? /lib/libglib-2.0.so.0 0 0x22dc2d8
    25 g_main_context_iteration /lib/libglib-2.0.so.0 0 0x22dc4b8
    26 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c7e455
    27 ?? /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x10e50b5
    28 QEventLoop::processEvents(QFlagsQEventLoop::ProcessEventsFlag) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c4e709
    29 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c4eb8a
    30 QCoreApplication::exec() /usr/local/Trolltech/Qt-4.7.1/lib/libQtCore.so.4 0 0x1c5313f
    31 QApplication::exec() /usr/local/Trolltech/Qt-4.7.1/lib/libQtGui.so.4 0 0x1022987
    32 main main.cpp 34 0x8056e5c@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Merinas
      wrote on 7 Mar 2011, 14:07 last edited by
      #2

      Maybe because your widget gets a QDeclarativeItem as parent witch is not a QWidget's child.

      1 Reply Last reply
      0
      • O Offline
        O Offline
        outdoor_guy
        wrote on 14 Mar 2011, 13:08 last edited by
        #3

        Sorry, I do not get it. Can you give me some more information what you mean.
        Maybe I had to mention that I'm a beginner in QT

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 14 Mar 2011, 13:57 last edited by
          #4

          I don't think you can simply use QWidgets as components in QML as you try to do. Components need to be QDeclarativeItem subclasses, and yours is not, it seems.

          Edit: PS, it is Qt (Uppercast Q, lowercast t), not QT. QT is QuickTime.

          1 Reply Last reply
          0

          1/4

          7 Mar 2011, 13:57

          • Login

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