New User: Can You Point Me to the Right Place
-
wrote on 11 Aug 2011, 21:54 last edited by
Hello Developers,
I am trying to get involved in a project that interests me. I have the source checked out through Gitorious, and am looking to get started. The portion I am specifically interested in is the portion of code that is responsible for rendering the actual widgets onto the screen (or the portion of code that interacts with the native APIs that render to the screen). Is there a good fourm to go for these types of things? Is there a recommended place in the documentation to start?
Thank you,
Matthew Hoggan -
wrote on 11 Aug 2011, 22:07 last edited by
Can you clarify a little bit more about what you're interested in? Are you new to Qt in general? Are you looking to learn so that you can develop apps, or are you trying to learn how things work under the hood. They're two quite different knowledge bases, and learning the internals of Qt definitely benefits from having a solid knowledge of how the toolkit works as a whole on the "outside." Likewise, using Qt doesn't require a real strong knowledge of what's going on under the hood.
If you're a new user in general, it may be best to start out by downloading the Qt SDK rather than starting by doing a build from source. While it's not an incredibly difficult task to build, it might be a good shortcut for you to be able to get started faster.
What platform are you using?
-
wrote on 11 Aug 2011, 23:14 last edited by
Sorry for the lack of clarification. I have developed two or three Qt applications in the past, as well as a few Win32 Applications and a few X11 applications. Thus, at this point I am more interested in learning how things work under the hood. What design patterns are used, what are the system calls being made etc. that make it possible for Qt's libraries to port across operating systems. I hope that clarifies things. If not please let me know and will restate myself again. To be specific I am interested only in the Graphical components of Qt such as their windows/dialog boxes (widgets). Other things such as event handling, signals, etc. are not of interest at this moment.
-
wrote on 12 Aug 2011, 02:34 last edited by
Before lighthouse grow up, you must read through the in QTDIR/src/gui/kernel
Take win32 for example,
At first, you should create an window class and register it
@
//from qapplication_win.cpp
const QString qt_reg_winclass(QWidget w)
{
...
WNDCLASS wc;
wc.style = style;
wc.lpfnWndProc = (WNDPROC)QtWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = qWinAppInst();
...
wc.lpszMenuName = 0;
wc.lpszClassName = (wchar_t)cname.utf16();
ATOM atom = RegisterClass(&wc);
...
@
this function will be called when you create an QWidget or QWidget's subclass.Second, you should define an callback function for the window
@
//
// QtWndProc() receives all messages from the main event loop
//
extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
MSG msg;
msg.hwnd = hwnd; // create MSG structure
msg.message = message; // time and pt fields ignored
msg.wParam = wParam;
msg.lParam = lParam;
msg.pt.x = GET_X_LPARAM(lParam);
msg.pt.y = GET_Y_LPARAM(lParam);
// If it's a non-client-area message the coords are screen coords, otherwise they are
// client coords.
if (message < WM_NCMOUSEMOVE || message > WM_NCMBUTTONDBLCLK)
ClientToScreen(msg.hwnd, &msg.pt);
...
// send through app filter
if (qApp->filterEvent(&msg, &res))
return res;
...
res = 0;
if (widget->winEvent(&msg, &res)) // send through widget filter
RETURN(res);
...
if (qt_is_translatable_mouse_event(message)) {
...
}else{
switch (message) {
...
case WM_MOUSEWHEEL:
case WM_MOUSEHWHEEL:
result = widget->translateWheelEvent(msg);
break;
...
}
...
@Then, call DispatchMessage to dispatch message:
@
bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
{
...
haveMessage = PeekMessage(&msg, 0, 0, 0, PM_REMOVE);
if (haveMessage && (flags & QEventLoop::ExcludeUserInputEvents)
&& ((msg.message >= WM_KEYFIRST
&& msg.message <= WM_KEYLAST)
|| (msg.message >= WM_MOUSEFIRST
...
|| msg.message == WM_CLOSE)) {
// queue user input events for later processing
haveMessage = false;
d->queuedUserInputEvents.append(msg);
}
if (haveMessage && (flags & QEventLoop::ExcludeSocketNotifiers)
&& (msg.message == WM_QT_SOCKETNOTIFIER && msg.hwnd == d->internalHwnd)) {
// queue socket events for later processing
haveMessage = false;
d->queuedSocketEvents.append(msg);
}
...
if (!filterEvent(&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
...
}
@
this function will be called in QApplication::exec(), QDialog::exec(), QMenu::exec()...At last, WinMain can be found at
@
//QTDIR\src\winmain\qtmain_win.cpp
/*
WinMain() - Initializes Windows and calls user's startup function main().
NOTE: WinMain() won't be called if the application was linked as a "console"
application.
*/
#ifdef Q_OS_WINCE
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR /wCmdParam/, int cmdShow)
#else
extern "C"
int APIENTRY WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR /cmdParamarg/, int cmdShow)
#endif
{
...
}
@If you can read Chinese, this blog will be useful for you. http://blog.csdn.net/dbzhang800/article/details/6370300
-
wrote on 12 Aug 2011, 02:56 last edited by
bq. WinMain() - Initializes Windows and calls user's startup function main().
NOTE: WinMain() won't be called if the application was linked as a "console"
applicationJust to see if I got this straight. So if you are compiling in Windows using minigw, cl.exe, or some other compiler for windows, WinMain( ) will still be recognized as the application entry point. This then allows WinMain to call your main (kind of like an initialization function). Once the users "main" function is called it would call QtApplication.exec( ) (if my memory serves me correctly) which would then create the Window set the windows call back function which routes all messages to your application?
Please correct me if I am wrong, or if I have construed your explanation.
-
wrote on 12 Aug 2011, 03:23 last edited by
WinMain() and main() are more complicated than you think.
An win32 gui program can have either WinMain or main as entry function. An console can have eigher WinMain or main as entry function too.
WinMain() in qtmain.lib (libqtmain.a), you can using the lib , but you can delete it too.
If you have code like this:
@
#include <windows.h>int main()
{
MessageBoxW (NULL, L"Hello World from main!", L"hello", MB_OK | MB_ICONINFORMATION);
return 0;
}int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nShowCmd)
{
MessageBoxW (NULL, L"Hello World from WinMain!", L"hello", MB_OK | MB_ICONINFORMATION);
return 0;
}
@If you use MSVC, you can select main or WinMain when complie the source code.
@
cl /EHsc hello.c /link /subsystem:windows user32.lib
cl /EHsc hello.c /link /subsystem:windows /entry:mainCRTStartup user32.lib
@If you use MinGW, you can not select WinMain whn main function exists, so, main() will be changed to qMain when you want to link the lib libqtmain.a
@
#if defined(QT_NEEDS_QMAIN)
int qMain(int, char **);
#define main qMain
#endif
@Note: I have written several blog about this, but all in Chinese language
http://blog.csdn.net/dbzhang800/article/details/6358996
http://hi.baidu.com/cyclone/blog/item/96624a90fb4ca081a977a4db.html
... -
wrote on 12 Aug 2011, 03:32 last edited by
I would like to read your blogs, but I don't speak or read a lick of Chinese and, Google translate isn't the best. Could you reference some of your sources in the blogs? I really don't mind reading, but sometimes it is good to ask before you start just reading anything. More time efficient. Btw thank you for your time in explaining this stuff to me, greatly appreciated. Do you have a freenode and/or irc channel, or Usenet group available?
--Matt
6/7