Guest User

Untitled

a guest
Jul 18th, 2021
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. programm:
  2. ```c++
  3. #include <QCoreApplication>
  4. #include <QObject>
  5.  
  6. class Counter : public QObject
  7. {
  8. Q_OBJECT
  9.  
  10. public:
  11. Counter() { m_value = 0; }
  12.  
  13. int value() const { return m_value; }
  14.  
  15. public slots:
  16. void setValue(int value);
  17.  
  18. signals:
  19. void valueChanged(int vewValue);
  20.  
  21. private:
  22. int m_value;
  23. };
  24.  
  25. void Counter::setValue(int value)
  26. {
  27. if(value != m_value) {
  28. m_value = value;
  29. emit valueChanged(value);
  30. }
  31. }
  32.  
  33. int main(int argc, char **argv)
  34. {
  35. QCoreApplication a(argc, argv);
  36. Counter ca, cb;
  37. QObject::connect(&ca, &Counter::valueChanged, &cb, &Counter::setValue);
  38.  
  39. return a.exec();
  40. }
  41.  
  42. ```
  43.  
  44. error:
  45. ```
  46. $ make
  47.  
  48. g++ -Wl,-O1 -o New4 main.o /usr/lib64/libQt5Core.so -lpthread
  49. /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: main.o: in function `Counter::setValue(int)':
  50. main.cpp:(.text+0x14): undefined reference to `Counter::valueChanged(int)'
  51. /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: main.o: in function `main':
  52. main.cpp:(.text.startup+0x58): undefined reference to `vtable for Counter'
  53. /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: main.cpp:(.text.startup+0x90): undefined reference to `Counter::valueChanged(int)'
  54. /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: main.cpp:(.text.startup+0x103): undefined reference to `Counter::staticMetaObject'
  55. collect2: error: ld returned 1 exit status
  56. mke: *** [Makefile:222: New4] Error 1
  57.  
  58. $
  59. ```
RAW Paste Data