Results 1 to 4 of 4

Thread: signal and slot

  1. #1
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default signal and slot

    i connect this in a (lets say setting.cpp), the slot is in another (lets say node.cpp)

    Qt Code:
    1. connect(ui.EDnameTxt, SIGNAL(textChanged(QString)), Node, SLOT(setText(QString)));
    To copy to clipboard, switch view to plain text mode 

    but when i compile it give me this error,

    1>.\settingswindow.cpp(57) : error C2275: 'Node' : illegal use of this type as an expression
    1> c:\texas instruments\node.h(62) : see declaration of 'Node'

    whats wrong with the declartion of my node.h???

    Qt Code:
    1. class Node : public QGraphicsItem, public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. typedef enum{ACCESS_POINT, END_DEVICE}NODE_TYPE;
    7. typedef struct
    8. {
    9. NODE_TYPE type;
    10. int addr;
    11. int xPos;
    12. int yPos;
    13. int strength;
    14. float temp;
    15. float voltage;
    16. int re;
    17.  
    18. int t_time_on;
    19. int fadeNumber;
    20. int fadeTime;
    21. int newNode;
    22. int deletedNode;
    23.  
    24. }NODE_DATA;
    25.  
    26. QBrush fill[40];
    27. Node(NetworkView *networkView);
    28. NODE_DATA nodeData;
    29. void addEdge(Edge *edge);
    30. QList<Edge *> edges() const;
    31.  
    32. enum { Type = UserType + 1 };
    33. int type() const { return Type; }
    34.  
    35. bool advance();
    36.  
    37. QRectF boundingRect() const;
    38. QPainterPath shape() const;
    39. void EDnamePreset();
    40. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    41.  
    42.  
    43. void setNodeData(int index);
    44. void updateData(int index);
    45. void AlertMessage();
    46. int getElapsedTime();
    47. void removeEdge(int childAddr = 0);
    48. int getAddr() { return nodeData.addr; }
    49. float getTemp() { return nodeData.temp; }
    50. int getType() { return nodeData.type; }
    51. void setTempUnit();
    52. void setColor(const NODE_TYPE type);
    53. int Node::find_active_node();
    54. void Node::current_updateData(int index);
    55.  
    56. int timerId () const;
    57.  
    58. /*struct colors{
    59. int alpha;
    60. int r;
    61. int g;
    62. int b;
    63. int newnodeflag;
    64. int delnodeflag;
    65. };
    66. struct colors node_colors[100];*/
    67. public slots:
    68. void EDnameChanged(int);
    69. void setText(const QString &newText){text = newText;}
    70.  
    71. protected:
    72. QVariant itemChange(GraphicsItemChange change, const QVariant &value);
    73.  
    74. void timerEvent(QTimerEvent *);
    75.  
    76. // NODE_DATA nodeData;
    77.  
    78. private:
    79. Ui_SettingsWindow ui;
    80. QList<Edge *> edgeList;
    81. QPointF newPos;
    82. NetworkView *graph;
    83. QPixmap pixmap,alpha_pix,back_pix,pixmap2,pix;
    84.  
    85. QColor nodeColor;
    86. QColor nodeColorDark;
    87. QColor AlertColor;
    88. QColor AlertColorDark;
    89. QColor DisAlertColorDark;
    90. QColor DisAlertColor;
    91.  
    92. QFont modeFont;
    93. QFont addrFont;
    94. QFont tempFont;
    95. QFont battFont;
    96. QFont strengthFont;
    97. QFont timeFont;
    98. QFont end_deviceFont;
    99. QFont keyFont;
    100. QFont smallFont;
    101. QFont txFont;
    102.  
    103. QTime timeStamp;
    104. QDate dateStamp;
    105.  
    106. NodeDb *pNodeDb;
    107.  
    108. // Flag used to highlight node.
    109. bool updated;
    110. int updateTimerId,fade_speed,updateTimerId2,updateTimerId3;
    111.  
    112. bool celsius;
    113. qreal arrowSize;
    114. double alertTemp;
    115. int alertDistance;
    116. int edStrength;
    117. QString nodeName;
    118. QString EDname;
    119. QString text;
    120. QString EDnameText;
    121. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal and slot

    Quote Originally Posted by Devoraz View Post
    i connect this in one .cpp
    Qt Code:
    1. connect(ui.EDnameTxt, SIGNAL(textChanged(QString)), Node, SLOT(setText(QString)));
    To copy to clipboard, switch view to plain text mode 
    You have to pass the address of object of Node class. Not Node class itself.
    Like this:
    Qt Code:
    1. Node nodeObj;
    2. connect(ui.EDnameTxt, SIGNAL(textChanged(QString)), &nodeObj, SLOT(setText(QString)));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: signal and slot

    Quote Originally Posted by yogeshgokul View Post
    You have to pass the address of object of Node class. Not Node class itself.
    Like this:
    Qt Code:
    1. Node nodeObj;
    2. connect(ui.EDnameTxt, SIGNAL(textChanged(QString)), &nodeObj, SLOT(setText(QString)));
    To copy to clipboard, switch view to plain text mode 
    i tried ur way, but it give em the following error....

    1>.\settingswindow.cpp(57) : error C2512: 'Node' : no appropriate default constructor available

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal and slot

    Quote Originally Posted by Devoraz View Post
    i tried ur way, but it give em the following error....1>.\settingswindow.cpp(57) : error C2512: 'Node' : no appropriate default constructor available
    OMG !!!
    That was an example. Please create instance of Node class according to available constructors. You have to pass this
    Qt Code:
    1. NetworkView *networkView
    To copy to clipboard, switch view to plain text mode 
    in constructor.

    Or create a default constructor.

Similar Threads

  1. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  2. retrieving signal name in a slot
    By Baschterl in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2008, 20:44
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Signal & Slot editor
    By Ishark in forum Qt Tools
    Replies: 4
    Last Post: 28th May 2008, 15:20
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.