Results 1 to 10 of 10

Thread: No such signal issue

  1. #1
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default No such signal issue

    PROBLEM:
    Qt Code:
    1. Object::connect: No such signal MTR::PawnBox::dragHasBegun(const MTR::PawnBox::Pawn*)
    To copy to clipboard, switch view to plain text mode 

    CODE:
    Qt Code:
    1. #ifndef PAWNBOX_SAFETY_DECLARATION
    2. #define PAWNBOX_SAFETY_DECLARATION
    3. class QPixmap;
    4. #include <QWidget>
    5. #include <QRectF>
    6. #include <QColor>
    7. #include <QMap>
    8.  
    9. namespace MTRUTIL {
    10. const int AMOUNT_OF_PAWNS = 8;
    11. }
    12.  
    13. namespace MTR {
    14. class PawnBox : public QWidget {
    15. Q_OBJECT
    16. public:
    17. PawnBox(QWidget *parent = 0);
    18. ~PawnBox() { delete px; }
    19. //klasa pionka
    20. class Pawn {
    21. public:
    22. Pawn();
    23. Pawn(QColor &color, QRectF &rec, QString &id);
    24. ~Pawn();
    25. const QColor &color() const { return color_; }
    26. const QRectF &rectF() const { return rectF_; }
    27. const QString &id() const { return id_; }
    28. const QPixmap &internalPicture() const { return dragPicture; }
    29. private:
    30. void paintInternalPicture();
    31. QColor color_;
    32. QRectF rectF_;
    33. QString id_;
    34. QPixmap dragPicture;
    35. };
    36. //
    37. signals:
    38. void dragHasBegun(const Pawn *pw);
    39. protected:
    40. void paintEvent(QPaintEvent *event);
    41. void mousePressEvent(QMouseEvent *event);
    42. void mouseMoveEvent(QMouseEvent *event);
    43. void dragMoveEvent(QDragMoveEvent *event);
    44. void dragEnterEvent(QDragEnterEvent *event);
    45. private:
    46. void startDrag();
    47. QPoint startPos;
    48. QPixmap *px;
    49. bool insidePawn;
    50. Pawn *draggedPawn;
    51. QMap<int, Pawn> pawnCollection;
    52. };
    53. }
    54. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void PawnBox::startDrag() {
    2. QMimeData *mimeData = new QMimeData;
    3. mimeData->setText(draggedPawn->id());
    4. QDrag *drag = new QDrag(this);
    5. drag->setPixmap(draggedPawn->internalPicture());
    6. drag->setMimeData(mimeData);
    7. drag->setHotSpot(QPoint(10,10));
    8.  
    9. drag->setDragCursor(*px,Qt::MoveAction);
    10. drag->setDragCursor(*px,Qt::CopyAction);
    11. const Pawn *pt = draggedPawn;
    12. emit dragHasBegun(pt);
    13. drag->start(Qt::MoveAction);
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef GAMEWIDGET_SAFETY_DECLARATION
    2. #define GAMEWIDGET_SAFETY_DECLARATION
    3. #include "../MTRPawnBox/mtrpawn.hpp"
    4. #include <QWidget>
    5.  
    6. namespace MTR {
    7. class GameWidget : public QWidget {
    8. Q_OBJECT
    9. public:
    10. GameWidget(QWidget *parent = 0);
    11. public slots:
    12. void setDraggedPawnPointer(const PawnBox::Pawn *pw);
    13. //void debugOne() { qDebug(draggedPawn->id().toStdString().c_str()); }
    14. protected:
    15. void paintEvent(QPaintEvent *event);
    16. void mousePressEvent(QMouseEvent *event);
    17. void mouseMoveEvent(QMouseEvent *event);
    18. void dragMoveEvent(QDragMoveEvent *event);
    19. void dragEnterEvent(QDragEnterEvent *event);
    20. private:
    21. MTR::PawnBox::Pawn *draggedPawn;
    22. };
    23. }
    24. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void GameWidget::setDraggedPawnPointer(const PawnBox::Pawn *pw) {
    2. if(pw) draggedPawn = const_cast<PawnBox::Pawn *>(pw);
    3. else draggedPawn = 0;
    4. }
    To copy to clipboard, switch view to plain text mode 

    All is connected in main window widget:
    Qt Code:
    1. connect(pawnBox,SIGNAL(dragHasBegun(const MTR::PawnBox::Pawn *)),gameScreen,SLOT(setDraggedPawnPointer(const MTR::PawnBox::Pawn *)));
    To copy to clipboard, switch view to plain text mode 
    where
    Qt Code:
    1. MTR::PawnBox *pawnBox;
    2. QWidget *firstMenuScreen;
    3. QWidget *rulesScreen;
    4. QWidget *resultsScreen;
    5. QWidget *gameChoiceScreen;
    6. QWidget *globalRecordsScreen;
    7. QWidget *localRecordsScreen;
    8. MTR::GameWidget *gameScreen;
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: No such signal issue

    I think you have to declare the signal as:
    Qt Code:
    1. void dragHasBegun(const MTR::PawnBox::Pawn*);
    To copy to clipboard, switch view to plain text mode 

    Moc takes things "literally".

    Regards

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

    mtrpoland (6th September 2007)

  4. #3
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: No such signal issue

    It worked.
    I wouldn't come up with such idea nor would I seek solution in this directory.
    I could have only groped for some solution.
    Thanks

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

    Default Re: No such signal issue

    OK. But I think you also have to use qRegisterMetatype in order to be able to pass custom types between signals and slots.

    Regards

  6. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: No such signal issue

    Quote Originally Posted by marcel View Post
    OK. But I think you also have to use qRegisterMetatype in order to be able to pass custom types between signals and slots.

    Regards
    Hmm.. you are partly right marcel.
    qRegisterMetaType doc says that the registering is need only for queued connections.
    I tried some of my own examples and from that i can conclude
    • If the parameter is pointer type no registering is needed for all connection type.
    • If the parameter is non pointer custom class type then registering is needed only
      when using queued connection.
      EDIT: The default connection is not queued.
    Last edited by Gopala Krishna; 6th September 2007 at 11:29.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: No such signal issue

    Well, I said "I think".

  8. #7
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: No such signal issue

    Quote Originally Posted by marcel View Post
    Well, I said "I think".
    You are right, but thanks actually for letting me know this. This is the first time i am encountering qRegisterMetaType's relation to signal/slots.
    Thanks for making me 'think'
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: No such signal issue

    Quote Originally Posted by Gopala Krishna View Post
    You are right, but thanks actually for letting me know this. This is the first time i am encountering qRegisterMetaType's relation to signal/slots.
    Thanks for making me 'think'
    OK, but I am not sure you are right, though...
    I never used qRegisterMetaType myself, but I was pretty sure that you have to register a custom type in order to use it with signals/slots.

    I'll make a test as soon as I get off work.

    Regards

  10. #9
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: No such signal issue

    Quote Originally Posted by marcel View Post
    OK, but I am not sure you are right, though...
    I never used qRegisterMetaType myself, but I was pretty sure that you have to register a custom type in order to use it with signals/slots.

    I'll make a test as soon as I get off work.

    Regards
    Did you test ?
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: No such signal issue

    When the type is not registered, you'll get a runtime warning about not being able to "queue arguments of type XXX" or something like that. I wouldn't rely on assuming the connection type - if you want to use a type in signal/slots connections (types, not pointers to them), it's better to register it. Note that it's also possible to declare a metatype for a type.

Similar Threads

  1. Replies: 3
    Last Post: 15th April 2007, 19:16
  2. textChanged signal issue
    By chaosgeorge in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2006, 00:32
  3. Replies: 2
    Last Post: 17th May 2006, 21:01
  4. no such signal QListBox::currentChanged()
    By jopie bakker in forum Newbie
    Replies: 2
    Last Post: 2nd March 2006, 15:17
  5. send signal from QCombobox
    By raphaelf in forum Qt Programming
    Replies: 22
    Last Post: 28th February 2006, 14:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.