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. Can Someone Explain "this" Portion of the Qt Framework?
Forum Updated to NodeBB v4.3 + New Features

Can Someone Explain "this" Portion of the Qt Framework?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 3.8k 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.
  • M Offline
    M Offline
    mehoggan
    wrote on last edited by
    #1

    In the tutorial found at ( :http://doc.qt.nokia.com/latest/widgets-tutorial.html ):

    You have the following code.
    @#include <QtGui>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QWidget window;
    window.resize(320, 240);
    window.show();
    window.setWindowTitle(
    QApplication::translate("toplevel", "Top-level widget"));
    return app.exec();
    }@

    Comming from a Win32 perspective is it the application that has all mesages directed to it from WndProc, and then it redirects those to the "top level" widget?

    If this is the case how does QApplication (QCoreApplication) know about the top level widget? What happens if the user never sets a top level widget?

    The way that I have normally redirect messages to my applications is by using the following code.

    @LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    HDC hDC;
    PAINTSTRUCT ps;

    static IController cntrl;
    cntrl = (IController
    )::GetWindowLongPtr(hWnd, GWL_USERDATA);

    if(uMsg == WM_NCCREATE)
    {
    cntrl = (IController*)(((CREATESTRUCT*)lParam)->lpCreateParams);
    ::SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG_PTR)cntrl);
    cntrl->CheckStatus();
    return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    ...@

    What is Qt doing differently from what I am doing to redirect calls to WndProc back into the class framework provided by Qt?

    Matthew Hoggan
    http://matthewh.me
    “It’s not wise to violate rules until you know how to observe them.” (t.s. eliot)

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Forget WIN32 for that, WIN32 API is a C based message API and not a C++ Object oriented API.

      Qt is object oriented.
      The important thing to do is:

      @
      QString text = ...;
      window.setWindowTitle(text);
      @

      This will handle setting the window title for you, however it is implemented internally (if you are interested, lok at the Qt source, it is different for the platforms and if the widget is top level or not).

      The second thing that happens is:

      @
      QString text = QApplication::translate("toplevel", "Top-level widget");
      @

      This is Qt's way of NLS handling. You could also write

      @
      QString text = "Top-level widget";
      @

      but then the text is never translated. By the way, the text is just text, nothing else. If it is top level or not, who cares?

      For Qt's "NLS handling, look here":http://doc.qt.nokia.com/4.7/internationalization.html
      There yopu see tr() method is used. tr is part of QObject. If you are in main, you are not inside a QObject, so how to call this function? The workaround is: "QApplication::translate":http://doc.qt.nokia.com/4.7/qcoreapplication.html#translate

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mehoggan
        wrote on last edited by
        #3

        bq. Forget WIN32 for that, WIN32 API is a C based message API and not a C++ Object oriented API

        I have been looking through the source, specifically at the portion of the code the deals with the Windows' windowing system, and Win32 is all over the place.

        bq. ...(if you are interested, lok at the Qt source, it is different for the platforms and if the widget is top level or not).

        I am interested in the internals, there is alot of source to go through. I find it well organized, however the level of abstraction to make Qt cross platform can be a bit of a headache. Could you point me to a good walkthrough of the Qt "kernel" (as the source calls it)?

        Matthew Hoggan
        http://matthewh.me
        “It’s not wise to violate rules until you know how to observe them.” (t.s. eliot)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          [quote author="mehoggan" date="1313648741"]bq. Forget WIN32 for that, WIN32 API is a C based message API and not a C++ Object oriented API

          I have been looking through the source, specifically at the portion of the code the deals with the Windows' windowing system, and Win32 is all over the place.
          [/quote]

          sure, internally, for the top level widget, it uses win32 calls. I don't know why you try to redirect calls? setting the window title in win32 SDK is done by WM_SETWINDOWTEXT

          [quote author="mehoggan" date="1313648741"]
          bq. ...(if you are interested, lok at the Qt source, it is different for the platforms and if the widget is top level or not).

          I am interested in the internals, there is alot of source to go through. I find it well organized, however the level of abstraction to make Qt cross platform can be a bit of a headache. Could you point me to a good walkthrough of the Qt "kernel" (as the source calls it)?[/quote]

          You have to study it on your own. I have already looked into many of the files, but only, If I need some info.
          The windows specific stuff for widgets is all in QWidget_win.cpp

          in this special part, it's:

          @
          void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
          {
          Q_Q(QWidget);
          if (!q->isWindow())
          return;

          Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
          SetWindowText(q->internalWinId(), (wchar_t*)caption.utf16());
          

          }
          @

          SetWindowText is the win32 API to do it, no need of message forwarding. This call is send to an HWND, normal windows behavior.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mehoggan
            wrote on last edited by
            #5

            bq. You have to study it on your own.

            I am trying, like I said in the first post there is a lot to work through.

            I am working on trying to figure out how the system initializes itself. For example, how does Qt allow you to bypass WinMain etc. If you could provide a "good" starting link that would be greatly appreciated.

            Thank you,

            Matthew Hoggan
            http://matthewh.me
            “It’s not wise to violate rules until you know how to observe them.” (t.s. eliot)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

              [quote author="mehoggan" date="1313656673"]bq. You have to study it on your own.

              I am trying, like I said in the first post there is a lot to work through.

              I am working on trying to figure out how the system initializes itself. For example, how does Qt allow you to bypass WinMain etc. If you could provide a "good" starting link that would be greatly appreciated.

              Thank you,[/quote]

              It does NOT bypass WinMain.

              https://qt.gitorious.org/qt/qt/blobs/master/src/winmain/qtmain_win.cpp

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                [quote author="peppe" date="1313656911"]
                It does NOT bypass WinMain.

                https://qt.gitorious.org/qt/qt/blobs/master/src/winmain/qtmain_win.cpp
                [/quote]

                Which means, you link the library qmain, which implements WinMain for you and then calls your custom main.

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mehoggan
                  wrote on last edited by
                  #8

                  Okay thanks for the input. So this behaves "somewhat" like MFC, in the since that the message pump and the WinMain site inside a DLL. Thank you for the clarification.

                  Matthew Hoggan
                  http://matthewh.me
                  “It’s not wise to violate rules until you know how to observe them.” (t.s. eliot)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    [quote author="mehoggan" date="1313658650"]Okay thanks for the input. So this behaves "somewhat" like MFC, in the since that the message pump and the WinMain site inside a DLL. Thank you for the clarification.[/quote]

                    yep
                    The message pump is your qApp->exec() call.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    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