QChekBox Problem
Verfasst: 12. September 2006 21:27
Ich will 3 QCheckBoxes in nem Widget positionieren und es darf immer nur 1 angekreutzt sein. wenn keins is wird das 1. genommen. My is das HauptWidget, Box die Checkbox, BoxHandler wacht dass nur 1 angekreutzt is
So jetzt kommt:
MSVCRTD.lib(cinitexe.obj) : warning LNK4098: Standardbibliothek "libcmtd.lib" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Bibliothek verwenden.
main.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual struct QMetaObject const * __thiscall Box::metaObject(void)const " (?metaObject@Box@@UBEPBUQMetaObject@@XZ)".
main.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual void * __thiscall Box::qt_metacast(char const *)" (?qt_metacast@Box@@UAEPAXPBD@Z)".
main.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual int __thiscall Box::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Box@@UAEHW4Call@QMetaObject@@HPAPAX@Z)".
debug\qt2.exe : fatal error LNK1120: 3 nicht aufgelöste externe Verweise.
NMAKE : fatal error U1077: ""E:\Progen\Microsoft Visual Studio 8\VC\bin\link.EXE"": R³ckgabe-Code "0x460"
Stop.
NMAKE : fatal error U1077: ""E:\Progen\Microsoft Visual Studio 8\VC\bin\nmake.exe"": R³ckgabe-Code "0x2"
Stop.
Code: Alles auswählen
#include<QApplication>
#include<QWidget>
#include<QVBoxLayout>
#include<QCheckBox>
class BoxHandler;
class Box:public QCheckBox
{
Q_OBJECT
public:
Box(BoxHandler** Handler,const QString & text,int num)
:QCheckBox(text,0),num(num),Handler(Handler)
{
connect(this,SIGNAL(stateChanged(int)),this,SLOT(sendToHandler(int)));
}
public slots:
void sendToHandler(int i);
private:
int num;
BoxHandler**Handler;
};
class BoxHandler
{
public:
BoxHandler(int numOfBoxes, Box**boxes)
:numOfBoxes(numOfBoxes),boxes(boxes)
{}
void setBox(int i)
{
switch(boxes[i]->checkState () )
{
case Qt::Unchecked:
{
boxes[0]->setCheckState(Qt::Checked);
}break;
case Qt::Checked:
{
for(int j=0;j<numOfBoxes;j++)
{
if(j==i);
else boxes[j]->setCheckState(Qt::Unchecked);
}
}break;
}
}
private:
int numOfBoxes;
Box**boxes;
};
void Box::sendToHandler(int i)
{
(*Handler)->setBox(num);
}
class My:public QWidget
{
public:
My()
:QWidget(0)
{
BoxHandler** Handler=new BoxHandler*();
Box**boxes=new Box*[3];
boxes[0]=new Box(Handler,"a",0);
boxes[0]->setCheckState(Qt::Checked);
boxes[1]=new Box(Handler,"b",1);
boxes[2]=new Box(Handler,"c",2);
*Handler=new BoxHandler(3,boxes);
QVBoxLayout*layout=new QVBoxLayout;
layout->addWidget(boxes[0]);
layout->addWidget(boxes[1]);
layout->addWidget(boxes[2]);
setLayout(layout);
}
};
int main(int argc, char*argv[])
{
QApplication*app=new QApplication(argc,argv);
My my;
my.show();
app->exec();
}MSVCRTD.lib(cinitexe.obj) : warning LNK4098: Standardbibliothek "libcmtd.lib" steht in Konflikt mit anderen Bibliotheken; /NODEFAULTLIB:Bibliothek verwenden.
main.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual struct QMetaObject const * __thiscall Box::metaObject(void)const " (?metaObject@Box@@UBEPBUQMetaObject@@XZ)".
main.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual void * __thiscall Box::qt_metacast(char const *)" (?qt_metacast@Box@@UAEPAXPBD@Z)".
main.obj : error LNK2001: Nicht aufgelöstes externes Symbol ""public: virtual int __thiscall Box::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Box@@UAEHW4Call@QMetaObject@@HPAPAX@Z)".
debug\qt2.exe : fatal error LNK1120: 3 nicht aufgelöste externe Verweise.
NMAKE : fatal error U1077: ""E:\Progen\Microsoft Visual Studio 8\VC\bin\link.EXE"": R³ckgabe-Code "0x460"
Stop.
NMAKE : fatal error U1077: ""E:\Progen\Microsoft Visual Studio 8\VC\bin\nmake.exe"": R³ckgabe-Code "0x2"
Stop.