PDA

View Full Version : Designer produces invalid code?



Tiansen
4th March 2008, 09:09
I use Designer, that is integrated inside Visual Studio. If I make a GUI class that inherits QPixmap, I get some errors regarding objectName and setObjectName. It seems that QPixmap does not inherit QObject?? And how it is that Designer does not know that?

wysota
4th March 2008, 09:45
What do you mean a GUI class that inherits QPixmap? In Designer? Could you explain?

Tiansen
4th March 2008, 11:08
OK, I will try to explain better. In Visual Studio I select Project -> Add Qt GUI Class. There is line edit field named "Base Class". If I type in QPixmap as base class, then code that is produced by Designer is invalid. I gett errors such as objectName is not a member of QPixmap and similar. If base class is QDialog or QWidget, there are obviously no errors because these two classes inherit QObject. Am I missing something here?

jpn
4th March 2008, 11:18
Am I missing something here?
Yes, you are responsible for writing a sensible class name there. Basically it could be a custom base class so no checks are made. Writing QPixmap there makes no sense because QPixmap is not a QWidget.

Tiansen
4th March 2008, 11:23
If I select Project -> Add Qt Class instead of Project -> Add GUI Qt Class, then constructor is invalid. I get this error:



error C2664: 'QPixmap::QPixmap(const QSize &)' : cannot convert parameter 1 from 'QObject*' to 'const QSize &'
1> Reason: cannot convert from 'QObject *' to 'const QSize'
1> No constructor could take the source type, or constructor overload resolution was ambiguous

It seems to me that Designer doesn't support adding QPixmap widget. If I am missing something please help me see how dumb I am ;)

Tiansen
4th March 2008, 11:25
jpn, so this means QPixmap does not originate from QObject either? I am just trying to display some image in my application. So it seems QPixmap is not the right class to use. Can you recommend me which class that IS widget should I use? Hmm, maybe QLabel would be better option?

jpn
4th March 2008, 11:37
jpn, so this means QPixmap does not originate from QObject either?
QPixmap is not GUI component. QPixmap only represents image data.


I am just trying to display some image in my application. So it seems QPixmap is not the right class to use. Can you recommend me which class that IS widget should I use? Hmm, maybe QLabel would be better option?
You should use one of the readily available options; QWidget, QDialog or QMainWindow. Then you will just add a QLabel widget on the form and set a pixmap on the label.

Tiansen
4th March 2008, 11:43
Yes, you are right. I did not know that I must use QLabel to display image. Now it works. Thank you very much!