PDA

View Full Version : "connect" failure



hgedek
10th August 2007, 13:31
Ok.In our project we are using a stackedWidget in another stackedWidget.In child stacked page we are using QGraphicsView-Item-Scene so I used
connect(&timeline,SIGNAL(frameChanged(int),,,,SLOT(setFrame ()));
but this didn't work.I realized that connect doesn't work.Because the slot doesn't work any.
I made debug and this is so.
SO:
Can we make connects in child widgets or made in parents?
Or:
What is our fault?

Thanks.

marcel
10th August 2007, 13:43
Did you start the timeline object? See QTimeLine::start()
.
Normally, that should trigger the signal after each duration() period passes.

BTW, that connect statement is not correct. Is it a typo or that is what you are using?

Regards

wysota
10th August 2007, 13:50
Check if connect() returns true or false and make sure you have console turned on when working on Windows.

hgedek
10th August 2007, 14:24
I created a small application and solved in it.The problem is connect because I cant use Q_OBJECT in project.But I could use it in application?
Two of them are same.But Why cant I use Q_OBJECT?

Error:
::MetaObject(...
::qtMetaCall(...

marcel
10th August 2007, 14:26
What are you talking about?

hgedek
10th August 2007, 14:31
error LNK 2001
That is the error message:

hgedek
10th August 2007, 14:40
error LNK 2001:virtual struct QMetaObject const * _thiscall Class::metaObject(void)cosnt...

Q_OBJECT error.

marcel
10th August 2007, 14:42
Unresolved external symbols?
You have to add the Q_OBJECT macro to your class. It is required when you use signals/slots.

Are you using Visual Studio? or just the ms compiler?
You will have to link with the object resulted from the source generated by moc. That is moc_your_Class_name.cpp.

Regards

hgedek
10th August 2007, 15:21
I am using visual Stiduo.
"You will have to link with the object resulted from the source generated by moc. That is moc_your_Class_name.cpp"

How will I do?

marcel
10th August 2007, 15:36
If you have the commercial edition of Qt and Visual Studio Integration , then it should already work.

Can you post some code? At least the class declaration.

Regards

hgedek
10th August 2007, 19:11
#ifndef __IMAGES_H_
#define __IMAGES_H_

#include <QtCore>
#include <QtGui>
class Images:public QObject,public QGraphicsPixmapItem
{
Q_OBJECT
public:
Images(const QPixmap &pixmap,QGraphicsItem *parent=0,QGraphicsScene *scene=0);
void adjust();
void startEvent();
void stopEvent();

private:
QTimeLine timeLine;
double z;

public slots:
void setFrame(int frame);

};

#endif


#include "Images.h"

Images::Images(const QPixmap& pixmap,QGraphicsItem *parent,QGraphicsScene *scene)
:QGraphicsPixmapItem(pixmap,parent,scene)
{
setAcceptsHoverEvents(true);
setFlags(QGraphicsItem::ItemIsFocusable);
setFlags(QGraphicsItem::ItemIsSelectable);
timeLine.setDuration(150);
timeLine.setFrameRange(0,150);
if(connect(&timeLine,SIGNAL(frameChanged(int)),this,SLOT(setFr ame(int)))==false)
{
QDialog *dialog=new QDialog;
dialog->resize(50,50);
dialog->show();
}
adjust();

}
void Images::adjust()
{
QMatrix matrix;
matrix.scale(120/boundingRect().width(),110/boundingRect().height());//Matrixing görevi
setMatrix(matrix);
//transformatin yapa
}
void Images::setFrame(int frame)
{
adjust();
QPointF center=boundingRect().center();

translate(center.x(),center.y());
scale(1+frame/330.0,1+frame/330.0);
translate(-center.x(),-center.y());

}
void Images::startEvent()
{
timeLine.setDirection(QTimeLine::Forward);
if (timeLine.state() == QTimeLine::NotRunning)
timeLine.start();
}

void Images::stopEvent()
{
timeLine.setDirection(QTimeLine::Backward);
if (timeLine.state() == QTimeLine::NotRunning)
timeLine.start();
}



#ifndef __IMENU_PAGE_H_
#define __IMENU_PAGE_H_

#include <QtGui>
#include "Images.h"


#define PICTURE_NUMBER 6

class ImenuPage:public QGraphicsView
{

Q_OBJECT
public:
ImenuPage(QWidget *parent=0);
void addItems();
void keyPressEvent(QKeyEvent *event);


private:

QGraphicsScene *scene;
QVector<Images *> images;
public slots:
void signalEvent(QKeyEvent *event);


};


#endif
#include "ImenuPage.h"

ImenuPage::ImenuPage(QWidget *parent)
:QGraphicsView(parent)
{

scene=new QGraphicsScene(this);
scene->setSceneRect(230, 100, 561, 321);
//setFixedSize(561, 321);
setScene(scene);

addItems();

}

void ImenuPage::addItems()
{
QStringList list;
list<<"A.png"<<"B.png"<<"C.png"<<"D.png"<<"E.png"<<"F.png";
int satir,sutun;
int index=0;
int imageOffset = 150;

int leftMargin = 270;
int topMargin = 120;

int columnOffset=0;
int x,y;

for(satir=0;satir<2;satir++)
{
y=topMargin+satir*140;

for(sutun=0;sutun<3;sutun++)
{
x=leftMargin+sutun*180;
Images* item=new Images(QPixmap(list[index]));
images.push_back(item);
scene->addItem(item);
item->setPos(x,y);
item->setData(0,index);
index++;

}
}
}

void ImenuPage::keyPressEvent(QKeyEvent *event)
{
static int index=0;
static int ilk=0;
if(ilk==0)
{
images[index]->startEvent();
index++;
ilk++;

}
else
{
images[index]->startEvent();
if(index==0)
images[PICTURE_NUMBER-1]->stopEvent();
else
images[index-1]->stopEvent();
index++;
}
index%=PICTURE_NUMBER;
}

void ImenuPage::signalEvent(QKeyEvent *event)
{
keyPressEvent(event);
}

Note:When I compiled using nmake, error wasnt seemed.Application worked.But I couldnt achieve using visual studio.(I have no commercial yet.Because we are in test still.In commercial application we will get.)

marcel
10th August 2007, 19:20
Note:When I compiled using nmake, error wasnt seemed.Application worked.But I couldnt achieve using visual studio.(I have no commercial yet.Because we are in test still.In commercial application we will get.)
Well, in this case, the moc isn't even getting generated.
If you compile using the makefile generated by qmake it is ok.

However, if you really want it, you can do the following for every header in your project that contains classes with the Q_OBJECT macro:
1. Go to the properties of the file( right click in solution explorer, properties);
2. In the General/Tool option, select "Custom build tool";
3. In custom build step:
- Command line: "$(QTDIR)\bin\moc.exe" -D_WINDOWS -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include" -I"." -I"$(QTDIR)\include\ActiveQt" -I".\debug" -I"." -I"$(QTDIR)\mkspecs\win32-msvc2005" "filename.h" -o "debug\moc_filename.cpp"
- Description: usually it is MOC filename
- Outputs: debug\moc_filename.cpp( depends on your target)
- Additional deps: $(QTDIR)\bin\moc.exe;filename.h

Remember you have to do this for each header that needs to be mocced.

Regards

hgedek
11th August 2007, 11:49
I changed the properties of Images.h(has Q_OBJECT) but there is no changes.It gave the same errors.
But when I changed .cpp file the error changed and another file gave error.This "another" file has the Images class object.It did not recognize the functions and constructor of this object.When I changed settings of this cpp file too,another one gave and so....

marcel
11th August 2007, 11:53
Could we see the errors?

hgedek
11th August 2007, 12:43
Orjinal Error:

Images.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Images::metaObject(void)const " (?metaObject@Images@@UBEPBUQMetaObject@@XZ)
Images.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall Images::qt_metacast(char const *)" (?qt_metacast@Images@@UAEPAXPBD@Z)
Images.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Images::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Images@@UAEHW4Call@QMetaObject@@HPAP AX@Z)
debug\s5xx.exe : fatal error LNK1120: 3 unresolved externals

Added Properties to Images.h:

- Command line: "$(QTDIR)\bin\moc.exe" -D_WINDOWS -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include" -I"." -I"$(QTDIR)\include\ActiveQt" -I".\debug" -I"." -I"$(QTDIR)\mkspecs\win32-msvc2005" "form\Images.h" -o "debug\moc_Images.cpp"
- Description: usually it is MOC filename(moc_Images)
- Outputs: debug\moc_Images.cpp( depends on your target)
- Additional deps: $(QTDIR)\bin\moc.exe;form\Images.h;

Errors:

Images.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Images::metaObject(void)const " (?metaObject@Images@@UBEPBUQMetaObject@@XZ)
Images.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall Images::qt_metacast(char const *)" (?qt_metacast@Images@@UAEPAXPBD@Z)
Images.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Images::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Images@@UAEHW4Call@QMetaObject@@HPAP AX@Z)
debug\s5xx.exe : fatal error LNK1120: 3 unresolved externals


Added Properties to Images.cpp:

ImenuPage.obj : error LNK2019: unresolved external symbol "public: __thiscall Images::Images(class QPixmap const &,class QGraphicsItem *,class QGraphicsScene *)" (??0Images@@QAE@ABVQPixmap@@PAVQGraphicsItem@@PAVQ GraphicsScene@@@Z) referenced in function "public: void __thiscall ImenuPage::addItems(void)" (?addItems@ImenuPage@@QAEXXZ)
ImenuPage.obj : error LNK2019: unresolved external symbol "public: void __thiscall Images::stopEvent(void)" (?stopEvent@Images@@QAEXXZ) referenced in function "public: virtual void __thiscall ImenuPage::keyPressEvent(class QKeyEvent *)" (?keyPressEvent@ImenuPage@@UAEXPAVQKeyEvent@@@Z)
ImenuPage.obj : error LNK2019: unresolved external symbol "public: void __thiscall Images::startEvent(void)" (?startEvent@Images@@QAEXXZ) referenced in function "public: virtual void __thiscall ImenuPage::keyPressEvent(class QKeyEvent *)" (?keyPressEvent@ImenuPage@@UAEXPAVQKeyEvent@@@Z)
debug\s5xx.exe : fatal error LNK1120: 3 unresolved externals

marcel
11th August 2007, 12:47
Added Properties to Images.h:

- Command line: "$(QTDIR)\bin\moc.exe" -D_WINDOWS -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include" -I"." -I"$(QTDIR)\include\ActiveQt" -I".\debug" -I"." -I"$(QTDIR)\mkspecs\win32-msvc2005" "form\Images.h" -o "debug\moc_Images.cpp"
- Description: usually it is MOC filename(moc_Images)
- Outputs: debug\moc_Images.cpp( depends on your target)
- Additional deps: $(QTDIR)\bin\moc.exe;form\Images.h;

- Command line: "$(QTDIR)\bin\moc.exe" -D_WINDOWS -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtCore" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include\QtGui" -I"$(QTDIR)\include" -I"." -I"$(QTDIR)\include\ActiveQt" -I".\debug" -I"." -I"$(QTDIR)\mkspecs\win32-msvc2005" "form\Images.h" -o "debug\moc_Images.cpp"
- Description: MOC Images.h
- Outputs: debug\moc_Images.cpp
- Additional deps: $(QTDIR)\bin\moc.exe;form\Images.h;

It still looks like you don't link with the meta object source or you don't even moc it.

Regards

wysota
11th August 2007, 12:51
Why don't you just use qmake to manage your project? You can even use its "-tp vc" option to generate a Visual Studio project from a qmake project and continue in VS directly.

hgedek
11th August 2007, 13:15
Thanks all.
"tp vc" solved problem.What is the difference between "t vcapp" and "tp vc"?We used first and now second one.

wysota
11th August 2007, 16:27
"tp" is "template prefix" whereas "t" is "template", thus if you have a TEMPLATE=lib and call -t vcapp, you'll get an application template instead of library template (which is not what you want) and if you use -tp vc it'll just add a vc prefix so you'll get vcapp or vclib depending on what the original template was.

So the bottom line is that it's better to use -tp vc because it always creates a proper project. It's usefull especially for running qmake with -r switch.