Can Someone Explain "this" Portion of the Qt Framework?
-
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?
-
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 -
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)?
-
[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.cppin 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.
-
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 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
-
[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.
-
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 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.