problems creating a custom widget (all code is done, but getting a weird compile error)
Ivica Bukvic
ico at fuse.net
Mon Nov 26 01:35:01 GMT 2001
Hi fellow qt/kde developers!
I am stuck yet once more, and am needing your generous assistance.
Basically, I followed Rolf Magnus's advice to create a derived class
from a LCDNumber widget so that I can have an lcd that could be clicked
on and by doing so have its value changed. So, here's the new class's
code:
>>>>>>>>>>>>>>>>>>>>>>>>>QLCD.h<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include <qlcdnumber.h>
#ifndef QLCD_H
#define QLCD_H
class QLCD : public QLCDNumber
{
public:
QLCD( QWidget *parent = 0, const char *name = 0 );
signals:
void lclicked();
void rclicked();
protected:
void mousePressEvent( QMouseEvent * );
virtual bool hitLCD( const QPoint &pos ) const;
};
#endif // QLCD_H
>>>>>>>>>>>>>>>>>>>>>>>>>QLCD.cpp<<<<<<<<<<<<<<<<<<<<<<<<<<<
#include "QLCD.h"
#include <qwidget.h>
#include <qpoint.h>
QLCD::QLCD( QWidget *parent, const char *name )
: QLCDNumber( parent, name )
{
}
void QLCD::mousePressEvent( QMouseEvent* event )
{
bool hit = hitLCD( e->pos() );
if ( hit ) {
if( event->button() == LeftButton ) {
emit lclicked();
}
if( event->button() == RightButton ) {
emit rclicked();
}
}
}
bool QLCD::hitLCD( const QPoint &pos ) const
{
return rect().contains( pos );
}
Then in the program I have obviously
#include "QLCD.h"
and in the constructor of the main QWidget:
NHour = new QLCD( TimerGroupBox, "NHour" );
NHour->setGeometry( QRect( 20, 20, 120, 110 ) );
cg.setColor( QColorGroup::Foreground, QColor( 85, 255, 0) );
cg.setColor( QColorGroup::Button, QColor( 85, 255, 0) );
cg.setColor( QColorGroup::Light, QColor( 170, 255, 127) );
cg.setColor( QColorGroup::Midlight, QColor( 127, 255, 63) );
cg.setColor( QColorGroup::Dark, QColor( 42, 127, 0) );
cg.setColor( QColorGroup::Mid, QColor( 57, 170, 0) );
cg.setColor( QColorGroup::Text, white );
cg.setColor( QColorGroup::BrightText, white );
cg.setColor( QColorGroup::ButtonText, white );
cg.setColor( QColorGroup::Base, black );
cg.setColor( QColorGroup::Background, black );
cg.setColor( QColorGroup::Shadow, black );
cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
cg.setColor( QColorGroup::HighlightedText, white );
pal.setActive( cg );
cg.setColor( QColorGroup::Foreground, QColor( 85, 255, 0) );
cg.setColor( QColorGroup::Button, QColor( 85, 255, 0) );
cg.setColor( QColorGroup::Light, QColor( 170, 255, 127) );
cg.setColor( QColorGroup::Midlight, QColor( 110, 255, 38) );
cg.setColor( QColorGroup::Dark, QColor( 42, 127, 0) );
cg.setColor( QColorGroup::Mid, QColor( 57, 170, 0) );
cg.setColor( QColorGroup::Text, white );
cg.setColor( QColorGroup::BrightText, white );
cg.setColor( QColorGroup::ButtonText, white );
cg.setColor( QColorGroup::Base, black );
cg.setColor( QColorGroup::Background, black );
cg.setColor( QColorGroup::Shadow, black );
cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
cg.setColor( QColorGroup::HighlightedText, white );
pal.setInactive( cg );
cg.setColor( QColorGroup::Foreground, QColor( 128, 128, 128) );
cg.setColor( QColorGroup::Button, QColor( 85, 255, 0) );
cg.setColor( QColorGroup::Light, QColor( 170, 255, 127) );
cg.setColor( QColorGroup::Midlight, QColor( 110, 255, 38) );
cg.setColor( QColorGroup::Dark, QColor( 42, 127, 0) );
cg.setColor( QColorGroup::Mid, QColor( 57, 170, 0) );
cg.setColor( QColorGroup::Text, white );
cg.setColor( QColorGroup::BrightText, white );
cg.setColor( QColorGroup::ButtonText, QColor( 128, 128, 128) );
cg.setColor( QColorGroup::Base, black );
cg.setColor( QColorGroup::Background, black );
cg.setColor( QColorGroup::Shadow, black );
cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
cg.setColor( QColorGroup::HighlightedText, white );
pal.setDisabled( cg );
NHour->setPalette( pal );
NHour->setCursor( QCursor( 5 ) );
NHour->setMouseTracking( FALSE );
NHour->setFocusPolicy( QLCDNumber::NoFocus );
NHour->setAcceptDrops( FALSE );
NHour->setAutoMask( FALSE );
NHour->setFrameShape( QLCDNumber::NoFrame );
NHour->setFrameShadow( QLCDNumber::Plain );
NHour->setLineWidth( 2 );
NHour->setMargin( 0 );
NHour->setMidLineWidth( 0 );
NHour->setSmallDecimalPoint( FALSE );
NHour->setNumDigits( 2 );
NHour->setSegmentStyle( QLCD::Filled );
NHour->setProperty( "intValue", 0 );
(most of this stuff is created by QT Designer having QLCDNumber, but
then I made appropriate changes so that it becomes QLCD (which is
derrived from QLCDNumber, so all of the parameters should be applicable
to that one as well).
So when I compile this app (which compiled error-free when using
QLCDNumber), everything compiles flawlessly until the very end when I
get this message:
rtmix.o: In function `QRect::height(void) const':
/usr/lib/qt2/include/qshared.h(.text+0x3bef): undefined reference to
`QLCD::QLCD(QWidget *, char const *)'
collect2: ld returned 1 exit status
gmake[2]: Leaving directory `/home/ico/RTMix-experimental/rtmix'
gmake[1]: Leaving directory `/home/ico/RTMix-experimental'
gmake[2]: *** [rtmix] Error 1
gmake[1]: *** [all-recursive] Error 1
gmake: *** [all-recursive-am] Error 2
*** failed ***
(rtmix is the name of the app and the main widget)
So from this I can see that my newly defined class is causing some kind
of conflict, but am not sure as to why. I've checked the
/usr/lib/qt2/include/qshared.h and it is a brief file whose function I
am unsure of. Here's its source:
#ifndef QSHARED_H
#define QSHARED_H
#ifndef QT_H
#include "qglobal.h"
#endif // QT_H
struct QShared
{
QShared() { count = 1; }
void ref() { count++; }
bool deref() { return !--count; }
uint count;
};
#endif // QSHARED_H
I am completely stuck at this point, so I would greatly appreciate any
help I could get on this one. Thank you very much! Sincerely,
Ivica Bukvic
-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«
More information about the KDevelop
mailing list