Results 1 to 14 of 14

Thread: Why Qt can not find a public slot?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Why Qt can not find a public slot?

    Hi.
    When I compile my application compiler says that it can't find two public slots.

    Qt Code:
    1. Object::connect: No such slot QWidget::geometryClicked(Geometry*,QPoint) in src/mwnd.cpp:28
    2. Object::connect: No such slot QWidget::mouseEventCoordinate(QMouseEvent*,QPointF) in src/mwnd.cpp:46
    To copy to clipboard, switch view to plain text mode 

    All the slots are defined in header and are writed in cpp file.

    This is the part of code where I connect SIGNAL in mc and l and SLOT in mwnd.
    Qt Code:
    1. mc = new MapControl( mapMcSize );
    2. mapadapter = new TileMapAdapter("robots.local", "/maps/maps/%1/%2/%3.png", 256, 0, 17);
    3. l = new MapLayer("Custom Layer", mapadapter);
    4. mc->addLayer(l);
    To copy to clipboard, switch view to plain text mode 

    27 - 28
    Qt Code:
    1. connect(l, SIGNAL( geometryClicked(Geometry*,QPoint) ),
    2. this, SLOT( geometryClicked(Geometry*,QPoint) ));
    To copy to clipboard, switch view to plain text mode 

    45-46
    Qt Code:
    1. connect(mc,SIGNAL(mouseEventCoordinate(const QMouseEvent*,QPointF)),
    2. this, SLOT(mouseEventCoordinate(QMouseEvent*,QPointF)));
    To copy to clipboard, switch view to plain text mode 


    Header:
    Qt Code:
    1. public slots:
    2. void geometryClicked(Geometry* geom, QPoint coord_px);
    3. void mouseEventCoordinate(QMouseEvent* event,QPointF point);
    To copy to clipboard, switch view to plain text mode 

    CPP:
    Qt Code:
    1. void mwnd::geometryClicked(Geometry *geom, QPoint)
    2. {
    3. if (geom->hasClickedPoints())
    4. {
    5. QList<Geometry*> pp = geom->clickedPoints();
    6. for (int i=0; i<pp.size(); i++)
    7. {
    8. QMessageBox::information(this, geom->name(), pp.at(i)->name());
    9. }
    10. }
    11. else if (geom->GeometryType == "Point")
    12. {
    13. QMessageBox::information(this, geom->name(), "just a point");
    14. }
    15. }
    16. void mwnd::mouseEventCoordinate(QMouseEvent *event,QPointF point)
    17. {
    18. QMessageBox::information(this, "Test", QString("%1 : %2").arg(point.x()).arg(point.y()));
    19. event->accept();
    20. }
    To copy to clipboard, switch view to plain text mode 

    What's I does wrong? Where is my mistake?
    (Sorry for bad english)

    PS I used qmapcontrol http://www.medieninf.de/qmapcontrol/
    Last edited by Alex Snet; 12th April 2009 at 19:24.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    In what class/function are you making the connections ?
    Have u used Q_OBJECT in ur class ?

  3. #3
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    for some reason, Qt is trying to find the slot in QWidget instead of ur mwnd class

    Qt Code:
    1. Object::connect: No such slot QWidget::geometryClicked(Geometry*,QPoint) in src/mwnd.cpp:28
    2. Object::connect: No such slot QWidget::mouseEventCoordinate(QMouseEvent*,QPointF) in src/mwnd.cpp:46
    To copy to clipboard, switch view to plain text mode 

    ..does ur class have any such parenting? could you elaborate a bit on code of mwnd?

  4. #4
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    Qt Code:
    1. #ifndef MWND_H
    2. #define MWND_H
    3.  
    4. #include <QWidget>
    5. #include <QSettings>
    6. #include "./../maps/qmapcontrol.h"
    7.  
    8. #include "thblackbutton.h"
    9. #include "thblackbar.h"
    10.  
    11. using namespace qmapcontrol;
    12. class mwnd : public QWidget
    13. {
    14. public:
    15. mwnd();
    16. ~mwnd();
    17.  
    18. MapControl* mc;
    19. MapAdapter* mapadapter;
    20.  
    21. QPointF coord1;
    22. QPointF coord2;
    23.  
    24. Layer* l;
    25. void createMapControl();
    26. // Settings
    27. QSettings sets;
    28.  
    29. public slots:
    30. void geometryClicked(Geometry* geom, QPoint coord_px);
    31. void mouseEventCoordinate(QMouseEvent* event,QPointF point);
    32.  
    33. protected:
    34. void resizeEvent(QResizeEvent *event);
    35. void wheelEvent(QWheelEvent *event);
    36. };
    37.  
    38. #endif // MWND_H
    To copy to clipboard, switch view to plain text mode 


    and cpp:

    Qt Code:
    1. #include "mwnd.h"
    2.  
    3. mwnd::mwnd()
    4. {
    5. QSize mapMcSize = sets.value("/mwnd/size",QSize(800,600)).value<QSize>();
    6. this->resize( mapMcSize );
    7.  
    8.  
    9. QPoint mapMcPos = sets.value("/mwnd/pos",QPoint(100,100)).value<QPoint>();
    10. this->move( mapMcPos );
    11.  
    12. mc = new MapControl( mapMcSize );
    13. mc->showScale(true);
    14. coord1 = QPointF();
    15. coord2 = QPointF();
    16.  
    17. mapadapter = new TileMapAdapter("robots.local", "/maps/maps/%1/%2/%3.png", 256, 0, 17);
    18.  
    19. // create a layer with the mapadapter and type MapLayer
    20. l = new MapLayer("Custom Layer", mapadapter);
    21. mc->addLayer(l);
    22.  
    23. // Add the Points and the QPen to a LineString
    24. LineString* ls = new LineString();
    25. // Add the LineString to the layer
    26. l->addGeometry(ls);
    27. connect(l, SIGNAL( geometryClicked(Geometry*,QPoint) ),
    28. this, SLOT( geometryClicked(Geometry*,QPoint) ));
    29.  
    30.  
    31. // create buttons as controls for zoom
    32. QPushButton* zoomin = new QPushButton("+");
    33. QPushButton* zoomout = new QPushButton("-");
    34. zoomin->setMaximumWidth(50);
    35. zoomout->setMaximumWidth(50);
    36. QSlider* zoomslider = new QSlider(Qt::Vertical,this);
    37. zoomslider->setMaximum(17);
    38. zoomslider->setMinimum(0);
    39. zoomslider->setMaximumHeight( 170 );
    40.  
    41. connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
    42. connect(zoomout, SIGNAL(clicked(bool)),mc, SLOT(zoomOut()));
    43. connect(zoomslider, SIGNAL(valueChanged(int)), mc, SLOT(setZoom(int)));
    44. connect(mc,SIGNAL(zoomChanged(int)), zoomslider, SLOT(setValue(int)));
    45. connect(mc,SIGNAL(mouseEventCoordinate(const QMouseEvent*,QPointF)),
    46. this, SLOT(mouseEventCoordinate(QMouseEvent*,QPointF)));
    47.  
    48.  
    49. // add zoom buttons to the layout of the MapControl
    50. QVBoxLayout* plusminusbtn = new QVBoxLayout;
    51. plusminusbtn->addWidget(zoomin);
    52. plusminusbtn->addWidget(zoomslider);
    53. plusminusbtn->addWidget(zoomout);
    54.  
    55.  
    56. // MapControl layout
    57. QVBoxLayout* innerlayout = new QVBoxLayout;
    58. innerlayout->addLayout(plusminusbtn);
    59. mc->setLayout(innerlayout);
    60.  
    61. //mc->setView(QPointF(0.00656,0.01929));
    62. // 55.809952,37.500973
    63. //GPS_Position pos = GPS_Position(1234567890 ,37.500973,"W",55.809952,"N");
    64. QPointF coord = sets.value("/mwnd/mc/pos",QPointF( 55.81 , 37.501 )).value<QPointF>();
    65. mc->setView( coord );
    66. int zoom = sets.value("/mwnd/mc/zoom", 15).value<int>();
    67. mc->setZoom(zoom);
    68.  
    69. ls->addPoint( new CirclePoint( coord.x(), coord.y(),"Start location", Point::Middle) );
    70.  
    71.  
    72. //QLabel* point;
    73. //innerlayout->addWidget( point );
    74. QTabWidget* tabs = new QTabWidget();
    75. tabs->addTab(mc, "Map");
    76. //layout->addWidget(mc);
    77.  
    78. QVBoxLayout* layout = new QVBoxLayout;
    79. layout->setSpacing(0);
    80. layout->setContentsMargins(0,0,0,0);
    81. layout->addWidget( tabs );
    82. this->setLayout(layout);
    83.  
    84. }
    85. mwnd::~mwnd()
    86. {
    87. sets.setValue("/mwnd/size",this->size());
    88. sets.setValue("/mwnd/pos",this->pos());
    89. sets.setValue("/mwnd/mc/pos", mc->currentCoordinate() );
    90. sets.setValue("/mwnd/mc/zoom",mc->currentZoom() );
    91. }
    92.  
    93. // Protected methods
    94. void mwnd::resizeEvent(QResizeEvent *event)
    95. {
    96. //mc->resize( (int) this->size().width(), (int) this->size().height() );
    97. //qDebug( QString("W: %1 H: %2").arg(this->size().width()).arg(this->size().height()).toAscii() );
    98. //mc->update();
    99. event->accept();
    100. //QWidget::resizeEvent(event);
    101. }
    102. void mwnd::wheelEvent(QWheelEvent *event)
    103. {
    104. int numDegrees = event->delta() / 8;
    105. int numSteps = numDegrees / 15;
    106.  
    107. if (event->orientation() == Qt::Horizontal) {
    108. // Change view
    109. } else {
    110. if(numSteps > 0)
    111. {
    112. if(mc->currentZoom()<17)
    113. {
    114. mc->zoomIn();
    115. }
    116. }
    117. else
    118. {
    119. if(mc->currentZoom()>0)
    120. {
    121. mc->zoomOut();
    122. }
    123. }
    124. }
    125. event->accept();
    126. }
    127. void mwnd::geometryClicked(Geometry *geom, QPoint)
    128. {
    129. if (geom->hasClickedPoints())
    130. {
    131. QList<Geometry*> pp = geom->clickedPoints();
    132. for (int i=0; i<pp.size(); i++)
    133. {
    134. QMessageBox::information(this, geom->name(), pp.at(i)->name());
    135. }
    136. }
    137. else if (geom->GeometryType == "Point")
    138. {
    139. QMessageBox::information(this, geom->name(), "just a point");
    140. }
    141. }
    142. void mwnd::mouseEventCoordinate(QMouseEvent *event,QPointF point)
    143. {
    144. QMessageBox::information(this, "Test", QString("%1 : %2").arg(point.x()).arg(point.y()));
    145. event->accept();
    146. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Why Qt can not find a public slot?

    You need the Q_OBJECT macro in the header of class mwnd.

  6. #6
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    Sorry? Can you write a sample?

  7. #7
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    Like this?
    Qt Code:
    1. using namespace qmapcontrol;
    2. class mwnd : public QWidget
    3. {
    4. Q_OBJECT
    5. public:
    6. mwnd(QWidget* parent = 0);
    7. ~mwnd();
    To copy to clipboard, switch view to plain text mode 

    If I write this - I recieve this:
    Qt Code:
    1. :-1: error: collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    can you post the whole error? this is just linker stopping cuz of some error that occured before

  9. #9
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    Sorry, I don't understand.
    I write all I have... Where is my bad?

  10. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    you have to rebuild your app after adding Q_OBJECT macro.
    so, do this
    make/mingw32-make/nmake clean
    qmake
    make/mingw32-make/nmake
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  11. #11
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why Qt can not find a public slot?

    Rebuilding and cleaning does not help =(

    Why the compiler can not find the socket if it was declared?

Similar Threads

  1. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44
  2. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  3. Replies: 1
    Last Post: 6th March 2007, 15:27
  4. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

Tags for this Thread

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.