PDA

View Full Version : Can't compile programs in Visual Studio.net 2005



xgoan
7th July 2006, 12:42
Warning 1 warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library MSVCRT.lib
Error 2 error LNK2019: unresolved external symbol "public: static struct QMetaObject const BotonesDialogo::staticMetaObject" (?staticMetaObject@BotonesDialogo@@2UQMetaObject@@ B) referenced in function "public: static class QString __cdecl BotonesDialogo::tr(char const *,char const *)" (?tr@BotonesDialogo@@SA?AVQString@@PBD0@Z) BotonesDialogo.obj
Error 3 error LNK2019: unresolved external symbol "protected: void __thiscall BotonesDialogo::accepted(void)" (?accepted@BotonesDialogo@@IAEXXZ) referenced in function "public: void __thiscall BotonesDialogo::accept(void)" (?accept@BotonesDialogo@@QAEXXZ) BotonesDialogo.obj
Error 4 error LNK2019: unresolved external symbol "protected: void __thiscall BotonesDialogo::canceled(void)" (?canceled@BotonesDialogo@@IAEXXZ) referenced in function "public: void __thiscall BotonesDialogo::cancel(void)" (?cancel@BotonesDialogo@@QAEXXZ) BotonesDialogo.obj
Error 5 error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall BotonesDialogo::metaObject(void)const " (?metaObject@BotonesDialogo@@UBEPBUQMetaObject@@XZ ) BotonesDialogo.obj
Error 6 error LNK2001: unresolved external symbol "public: virtual void * __thiscall BotonesDialogo::qt_metacast(char const *)" (?qt_metacast@BotonesDialogo@@UAEPAXPBD@Z) BotonesDialogo.obj
Error 7 error LNK2001: unresolved external symbol "public: virtual int __thiscall BotonesDialogo::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@BotonesDialogo@@UAEHW4Call@QMetaObje ct@@HPAPAX@Z) BotonesDialogo.obj
Error 8 fatal error LNK1120: 6 unresolved externals c:\Chus\QT\Widgets\BotonesDialogo\release\BotonesD ialogo.exe 1


It occours only when I try to use 'emit' word, thanks :)

The code:

BotonesDialogo.cpp:

#include "BotonesDialogo.h"

#include <QHBoxLayout>
#include <QPushButton>

BotonesDialogo::BotonesDialogo(QWidget *parent):QWidget(parent){
QPushButton *accept=new QPushButton;
accept->setText(tr("&Aceptar"));
QPushButton *cancel=new QPushButton;
cancel->setText(tr("&Cancelar"));

connect(accept,SIGNAL(clicked()),this,SLOT(accept( )));
connect(cancel,SIGNAL(clicked()),this,SLOT(cancel( )));

QHBoxLayout *hLayout=new QHBoxLayout;
hLayout->setAlignment(Qt::AlignRight | Qt::AlignBottom);
hLayout->addWidget(accept);
hLayout->addWidget(cancel);
setLayout(hLayout);
}

void BotonesDialogo::accept(){
emit accepted();
}

void BotonesDialogo::cancel(){
emit canceled();
}

BotonesDialogo.h:

#ifndef __BOTONESDIALOGO_H_
#define __BOTONESDIALOGO_H_

#include <QWidget>

class BotonesDialogo:public QWidget{
Q_OBJECT

public:
BotonesDialogo(QWidget *parent=0);
public slots:
void accept();
void cancel();
signals:
void accepted();
void canceled();
};

#endif

main.cpp:

#include <QApplication>
#include "BotonesDialogo.h"

int main(int argc,char *argv[]){
QApplication app(argc,argv);

BotonesDialogo prueba;
prueba.show();

return app.exec();
}

Thank's

munna
7th July 2006, 13:07
The problem is because both your button names and the slot names are same.

accept,accept()
cancel,cancel()

Also, you will have memory leak since the buttons will not be deleted.

You should have something like



QPushButton *acceptButton = new QPushButton(tr("yourText"),this);
connect(accpetButton,SIGNAL(clicked()),this,SLOT(a ccept()));

jacek
7th July 2006, 13:14
It occours only when I try to use 'emit' word
Did you run moc program on your sources to generate signals & slots implementation? If you use qmake, you must re-run it to generate a new Makefile every time you add a Q_OBJECT macro.


The problem is because both your button names and the slot names are same.

accept,accept()
cancel,cancel()
That shouldn't be a problem in this case, since SLOT and SIGNAL macros convert their parameter to strings.


Also, you will have memory leak since the buttons will not be deleted.
Right, those buttons should have a parent.

xgoan
7th July 2006, 14:10
Ouch. hehe. I will try it.

I'm just learning Qt now.

Thank you