Funny thing about that: I tried both the QApplication (that one took awhile to figure out the .pro file) and QCoreApplication, and they both give the same error. The error comes from the QTcpSocket constructor, not from the application. The bizarre part is that it seems that the QTcpSocket was created anyway, and while QCoreApplication ignores it, Qapplication goes ahead anyway and is happy with my QObject::connect(...) stuff and it works, so I don't know what it's complaining about.

Bottom line: My code works, but something, somewhere, is still not ok.

Note: This is a QConsole project. Here is my .pro file:
Qt Code:
  1. QT += core gui network
  2.  
  3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  4.  
  5. TARGET = testing_1
  6. CONFIG += console
  7. CONFIG -= app_bundle
  8.  
  9. TEMPLATE = app
  10.  
  11.  
  12. SOURCES += main.cpp
  13.  
  14. HEADERS +=
  15.  
  16.  
  17. INCLUDEPATH += tmp/moc/release_shared
  18.  
  19. unix|win32: LIBS += -L$$PWD/../../../../../Qt/4.8.5/lib/ -lQtCore4
  20.  
  21. INCLUDEPATH += $$PWD/../../../../../Qt/4.8.5/include
  22. DEPENDPATH += $$PWD/../../../../../Qt/4.8.5/include
To copy to clipboard, switch view to plain text mode 


Here is my latest experimental code if you're interested:
Qt Code:
  1. #include <QApplication>
  2. #include <QtCore/QCoreApplication>
  3.  
  4. #include <iostream>
  5. using std::cout;
  6. using std::endl;
  7.  
  8. #include <QtDebug>
  9. #include <QObject>
  10. #include <QtNetwork/QTcpSocket>
  11.  
  12.  
  13. class my_TCP_Q_socket_with_readyRead : public QObject
  14. {
  15. public:
  16. explicit my_TCP_Q_socket_with_readyRead(QObject *parent = 0) :
  17. QObject(parent)
  18. {
  19. // ??why are you not ok taking "this" as an argument ?!
  20. m_socket_ptr = new QTcpSocket(this);
  21.  
  22. m_socket_ptr->connectToHost("10.10.10.126", 5);
  23. if (!(m_socket_ptr->waitForConnected((5000))))
  24. {
  25. qDebug() << "not connected";
  26. m_socket_ptr = NULL;
  27. }
  28. else
  29. {
  30. qDebug() << "connected";
  31. }
  32.  
  33. QObject::connect(
  34. m_socket_ptr,
  35. SIGNAL(readyRead()),
  36. this,
  37. SLOT(read_it()));
  38. }
  39.  
  40.  
  41. // http://qt-project.org/wiki/Qt_for_beginners_Signals_and_slots_2
  42. // "Even if the signal is declared as a method, there is no
  43. // need to implement it. The meta-object compiler is used to
  44. // do this."
  45. Q_SIGNAL void done_reading(int num);
  46.  
  47. private:
  48. Q_OBJECT
  49.  
  50. QTcpSocket *m_socket_ptr;
  51. QByteArray m_arr;
  52.  
  53. Q_SLOT void read_it()
  54. {
  55. static int read_count = 0;
  56. qint64 bytes_available = m_socket_ptr->bytesAvailable();
  57.  
  58. if (bytes_available > 0)
  59. {
  60. read_count += 1;
  61.  
  62. qDebug() << "Reading '" << bytes_available << "' bytes";
  63. m_arr = m_socket_ptr->readAll();
  64. qDebug() << m_arr;
  65. }
  66.  
  67. emit done_reading(read_count);
  68. }
  69. };
  70.  
  71.  
  72. class my_class : public QObject
  73. {
  74. public:
  75. explicit my_class(QObject *parent = 0) :
  76. QObject(parent)
  77. {
  78.  
  79. }
  80.  
  81. Q_SLOT void say_something(int num)
  82. {
  83. cout << "hey there! number is '" << num << "'" << endl;
  84. }
  85.  
  86. private:
  87. Q_OBJECT
  88. };
  89.  
  90.  
  91. #include "main.moc"
  92.  
  93. int main(int argc, char *argv[])
  94. {
  95. int app_ret_val = 0;
  96. //QApplication app(argc, argv);
  97. QCoreApplication app(argc, argv);
  98.  
  99. my_TCP_Q_socket_with_readyRead s;
  100. my_class mc;
  101.  
  102. QObject::connect(&s, SIGNAL(done_reading(int)), &mc, SLOT(say_something(int)));
  103.  
  104. app_ret_val = app.exec();
  105.  
  106.  
  107. return app_ret_val;
  108. }
To copy to clipboard, switch view to plain text mode 

I've been trying to hunt down how the basic QTcpSocket constructor is supposed work with the "this" argument. It is supposed to "just work" from the demos that I have seen, so I don't know where to to do when it doesn't work. Any more ideas?