PDA

View Full Version : errors



manu
14th June 2008, 17:32
Alright so here is my simple code...

header.cpp


#include<QLabel>
#include<QPushButton>
#include<QVBoxLayout>
#include<QCheckBox>
#include<QLineEdit>

#include"header.h"


widg::widg(QWidget *parent)
: QWidget(parent)
{

label = new QLabel(tr("Find What"));
line = new QLineEdit;
label->setBuddy(line);

close = new QPushButton(tr("Close"));
close->resize(50,30);

find = new QPushButton(tr("Find"));
find->resize(50,30);
find->setEnabled(false);
find->setDefault(true);

casechk = new QCheckBox(tr("Case Sensitive"));
back = new QCheckBox(tr("Backward Search"));

connect(close,SIGNAL(clicked()),this,SLOT(quit())) ;
connect(line,SIGNAL(textChanged(const QString &)),this,SLOT(enableFind(const QString &)));
connect(find,SIGNAL(clicked()),this,SLOT(findClick ed()));

QVBoxLayout *lay= new QVBoxLayout;
lay->addWidget(label);
lay->addWidget(line);
lay->addWidget(casechk);
lay->addWidget(back);
lay->addWidget(find);
lay->addWidget(close);
setLayout(lay);

}

void widg::findClicked()
{
QString text = line->text();

Qt::CaseSensitivity ct = casechk->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;

if(back->isChecked())
{
emit findprev(text, ct);
}
else
{
emit findnext(text, ct);
}
}

void widg::enableFind(const QString &text)
{
find->setEnabled(true);
}


the header file



#ifndef HEADER_H
#define HEADER_H

#include<QWidget>

class QLabel;
class QPushButton;
class QLineEdit;
class QCheckBox;

class widg:public QWidget
{

public:

widg(QWidget *parent = 0);

private slots:

void findClicked();
void enableFind(const QString &text);

signals:

void findnext(const QString &str, Qt::CaseSensitivity cs);
void findprev(const QString &str, Qt::CaseSensitivity cs);

private:

QLabel *label;
QLineEdit *line;
QPushButton *find;
QPushButton *close;
QCheckBox *casechk;
QCheckBox *back;
};

#endif


and the main


#include<QApplication>


#include"header.h"


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

widg widget;
widget.show();

return app.exec();
}


and i get the following error message


Linking...
header.obj : error LNK2001: unresolved external symbol "protected: void __thiscall widg::findnext(class QString const &,enum Qt::CaseSensitivity)" (?findnext@widg@@IAEXABVQString@@W4CaseSensitivity @Qt@@@Z)
header.obj : error LNK2001: unresolved external symbol "protected: void __thiscall widg::findprev(class QString const &,enum Qt::CaseSensitivity)" (?findprev@widg@@IAEXABVQString@@W4CaseSensitivity @Qt@@@Z)
release/r4.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

r4.exe - 3 error(s), 0 warning(s)


i don't know what to do..!! please help...!!

JimDaniel
14th June 2008, 18:11
Just add Q_OBJECT macro to your header file and it will compile.



#ifndef HEADER_H
#define HEADER_H

#include<QWidget>

class QLabel;
class QPushButton;
class QLineEdit;
class QCheckBox;

class widg:public QWidget
{
Q_OBJECT

public:

widg(QWidget *parent = 0);

private slots:

void findClicked();
void enableFind(const QString &text);

signals:

void findnext(const QString &str, Qt::CaseSensitivity cs);
void findprev(const QString &str, Qt::CaseSensitivity cs);

private:

QLabel *label;
QLineEdit *line;
QPushButton *find;
QPushButton *close;
QCheckBox *casechk;
QCheckBox *back;
};

#endif

manu
15th June 2008, 07:04
ok...I tried putting Q_OBJECT in my header file...now i am getting 6 errors...



--------------------Configuration: r1 - Win32 Release--------------------
Running MOC on ..\..\..\test5\header.h
Compiling...
moc_header.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval2(int)" (?setval2@widg@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval1(int)" (?setval1@widg@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall cannonfld::cannonfld(class QWidget *)" (??0cannonfld@@QAE@PAVQWidget@@@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng2(int,int)" (?setrng2@widg@@QAEXHH@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng1(int,int)" (?setrng1@widg@@QAEXHH@Z)
release/r1.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.

r1.exe - 6 error(s), 0 warning(s)


what i want to knw is why is it displaying errors in the functions which don't exist anywhere in my code...??




main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval2(int)" (?setval2@widg@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setval1(int)" (?setval1@widg@@QAEXH@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall cannonfld::cannonfld(class QWidget *)" (??0cannonfld@@QAE@PAVQWidget@@@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng2(int,int)" (?setrng2@widg@@QAEXHH@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall widg::setrng1(int,int)" (?setrng1@widg@@QAEXHH@Z)
release/r1.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.

r1.exe - 6 error(s), 0 warning(s)

JimDaniel
15th June 2008, 15:54
I'm not sure. Are these functions you had in there but took out? If so, assuming you're using Visual Studio, go to Build->Clean Solution, then Build->Rebuild Solution. See if that helps.

manu
16th June 2008, 12:29
ahhh...!!! got it.... thanks mate.... it worked...