Results 1 to 19 of 19

Thread: "connect" failure

  1. #1
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default "connect" failure

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: "connect" failure

    Check if connect() returns true or false and make sure you have console turned on when working on Windows.

  4. The following user says thank you to wysota for this useful post:

    hgedek (10th August 2007)

  5. #4
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    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(...

  6. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure

    What are you talking about?

  7. The following user says thank you to marcel for this useful post:

    hgedek (10th August 2007)

  8. #6
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    error LNK 2001
    That is the error message:

  9. #7
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    error LNK 2001:virtual struct QMetaObject const * _thiscall Class::metaObject(void)cosnt...

    Q_OBJECT error.

  10. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure

    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

  11. The following user says thank you to marcel for this useful post:

    hgedek (10th August 2007)

  12. #9
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    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?

  13. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure

    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

  14. #11
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    Qt Code:
    1. #ifndef __IMAGES_H_
    2. #define __IMAGES_H_
    3.  
    4. #include <QtCore>
    5. #include <QtGui>
    6. class Images:public QObject,public QGraphicsPixmapItem
    7. {
    8. Q_OBJECT
    9. public:
    10. Images(const QPixmap &pixmap,QGraphicsItem *parent=0,QGraphicsScene *scene=0);
    11. void adjust();
    12. void startEvent();
    13. void stopEvent();
    14.  
    15. private:
    16. QTimeLine timeLine;
    17. double z;
    18.  
    19. public slots:
    20. void setFrame(int frame);
    21.  
    22. };
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "Images.h"
    2.  
    3. Images::Images(const QPixmap& pixmap,QGraphicsItem *parent,QGraphicsScene *scene)
    4. :QGraphicsPixmapItem(pixmap,parent,scene)
    5. {
    6. setAcceptsHoverEvents(true);
    7. setFlags(QGraphicsItem::ItemIsFocusable);
    8. setFlags(QGraphicsItem::ItemIsSelectable);
    9. timeLine.setDuration(150);
    10. timeLine.setFrameRange(0,150);
    11. if(connect(&timeLine,SIGNAL(frameChanged(int)),this,SLOT(setFrame(int)))==false)
    12. {
    13. QDialog *dialog=new QDialog;
    14. dialog->resize(50,50);
    15. dialog->show();
    16. }
    17. adjust();
    18.  
    19. }
    20. void Images::adjust()
    21. {
    22. QMatrix matrix;
    23. matrix.scale(120/boundingRect().width(),110/boundingRect().height());//Matrixing görevi
    24. setMatrix(matrix);
    25. //transformatin yapa
    26. }
    27. void Images::setFrame(int frame)
    28. {
    29. adjust();
    30. QPointF center=boundingRect().center();
    31.  
    32. translate(center.x(),center.y());
    33. scale(1+frame/330.0,1+frame/330.0);
    34. translate(-center.x(),-center.y());
    35.  
    36. }
    37. void Images::startEvent()
    38. {
    39. timeLine.setDirection(QTimeLine::Forward);
    40. if (timeLine.state() == QTimeLine::NotRunning)
    41. timeLine.start();
    42. }
    43.  
    44. void Images::stopEvent()
    45. {
    46. timeLine.setDirection(QTimeLine::Backward);
    47. if (timeLine.state() == QTimeLine::NotRunning)
    48. timeLine.start();
    49. }
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. #ifndef __IMENU_PAGE_H_
    2. #define __IMENU_PAGE_H_
    3.  
    4. #include <QtGui>
    5. #include "Images.h"
    6.  
    7.  
    8. #define PICTURE_NUMBER 6
    9.  
    10. class ImenuPage:public QGraphicsView
    11. {
    12.  
    13. Q_OBJECT
    14. public:
    15. ImenuPage(QWidget *parent=0);
    16. void addItems();
    17. void keyPressEvent(QKeyEvent *event);
    18.  
    19.  
    20. private:
    21.  
    22. QVector<Images *> images;
    23. public slots:
    24. void signalEvent(QKeyEvent *event);
    25.  
    26.  
    27. };
    28.  
    29.  
    30. #endif
    31. #include "ImenuPage.h"
    32.  
    33. ImenuPage::ImenuPage(QWidget *parent)
    34. :QGraphicsView(parent)
    35. {
    36.  
    37. scene=new QGraphicsScene(this);
    38. scene->setSceneRect(230, 100, 561, 321);
    39. //setFixedSize(561, 321);
    40. setScene(scene);
    41.  
    42. addItems();
    43.  
    44. }
    45.  
    46. void ImenuPage::addItems()
    47. {
    48. list<<"A.png"<<"B.png"<<"C.png"<<"D.png"<<"E.png"<<"F.png";
    49. int satir,sutun;
    50. int index=0;
    51. int imageOffset = 150;
    52.  
    53. int leftMargin = 270;
    54. int topMargin = 120;
    55.  
    56. int columnOffset=0;
    57. int x,y;
    58.  
    59. for(satir=0;satir<2;satir++)
    60. {
    61. y=topMargin+satir*140;
    62.  
    63. for(sutun=0;sutun<3;sutun++)
    64. {
    65. x=leftMargin+sutun*180;
    66. Images* item=new Images(QPixmap(list[index]));
    67. images.push_back(item);
    68. scene->addItem(item);
    69. item->setPos(x,y);
    70. item->setData(0,index);
    71. index++;
    72.  
    73. }
    74. }
    75. }
    76.  
    77. void ImenuPage::keyPressEvent(QKeyEvent *event)
    78. {
    79. static int index=0;
    80. static int ilk=0;
    81. if(ilk==0)
    82. {
    83. images[index]->startEvent();
    84. index++;
    85. ilk++;
    86.  
    87. }
    88. else
    89. {
    90. images[index]->startEvent();
    91. if(index==0)
    92. images[PICTURE_NUMBER-1]->stopEvent();
    93. else
    94. images[index-1]->stopEvent();
    95. index++;
    96. }
    97. index%=PICTURE_NUMBER;
    98. }
    99.  
    100. void ImenuPage::signalEvent(QKeyEvent *event)
    101. {
    102. keyPressEvent(event);
    103. }
    To copy to clipboard, switch view to plain text mode 
    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.)
    Last edited by wysota; 10th August 2007 at 21:43. Reason: missing [code] tags

  15. #12
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure

    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

  16. The following user says thank you to marcel for this useful post:

    hgedek (11th August 2007)

  17. #13
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    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....

  18. #14
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure

    Could we see the errors?

  19. #15
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    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

  20. #16
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: "connect" failure


    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

  21. The following user says thank you to marcel for this useful post:

    hgedek (11th August 2007)

  22. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: "connect" failure

    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.

  23. The following user says thank you to wysota for this useful post:

    hgedek (11th August 2007)

  24. #18
    Join Date
    Jul 2007
    Posts
    104
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default Re: "connect" failure

    Thanks all.
    "tp vc" solved problem.What is the difference between "t vcapp" and "tp vc"?We used first and now second one.

  25. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: "connect" failure

    "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.

Similar Threads

  1. qmake failure for SUBDIRS template on OSX
    By lonejedi in forum Newbie
    Replies: 3
    Last Post: 24th May 2010, 00:02
  2. QWT assert failure
    By Andimat in forum Qwt
    Replies: 1
    Last Post: 21st June 2007, 14:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.