PDA

View Full Version : QApplication::desktop() incomplete type



codebehind
18th August 2008, 12:40
I've done a new step - move to QT4

i try to port some old test apps and the next line of code:

width=QApplication::desktop()->width();
returns error while compiling

error: invalid use of incomplete type ‘struct QDesktopWidget’

i haven't noticed any diff between Qt3 and Qt4 docs.

lyuts
18th August 2008, 13:00
did you include QDesktopWidget.h ?

codebehind
18th August 2008, 20:18
No. thanks. it works.

I don't really understand why?
I'm using QApplication and its function. I thought it was enough to include QApplication?

jacek
18th August 2008, 20:41
I'm using QApplication and its function. I thought it was enough to include QApplication?
Read a bit about forward declarations.

http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.11

codebehind
19th August 2008, 10:50
thanks for the link jacek. It makes things a little more clear but still does not explain me why I could compile this code with qt3 and with qt4 i couldn't?
i've looked in qapplication.h and there is no forward declaration.

jacek
19th August 2008, 18:53
why I could compile this code with qt3 and with qt4 i couldn't?
Because Qt4 sources are organised differently. Now the compiler must read QDesktopWidget code only when you really use it.


i've looked in qapplication.h and there is no forward declaration.
Check again. Look near QT_MODULE macro.

codebehind
21st August 2008, 19:01
Check again. Look near QT_MODULE macro.
sorry. i was thinking about qt3 - qapplication.h

jacek
21st August 2008, 19:08
i was thinking about qt3 - qapplication.h
In that case everything is OK. That's the difference between Qt3 and Qt4 --- Qt4 uses forward declaration.