Results 1 to 16 of 16

Thread: QMetaObject use in visual studio (or "asyncronous QSocketNotifier use")

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    May 2014
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMetaObject use in visual studio (or "asyncronous QSocketNotifier use")

    ...it is a signal just like QSocketNotifier::activated(), so it is connected to a slot...
    I'm not following. What is a "signal"? And what is a "slot"? They are preprocessor macros for "qFlagLocation("1"#a QLOCATION)" and "qFlagLocation("2"#a QLOCATION)", respectively.

    This is because the example uses blocking I/O, so it calls waitForReadyRead instead of connecting to readRead()
    What do you mean, "connecting to"? How would you "connect" to a preprocessor macro? What does that even mean?


    Added after 42 minutes:


    Also, I've been looking at the example you linked to, trying to tear it apart and get it working. I'm running into an error in my "connect(...)" call again, in which it cannot find the function specified in the fourth argument (the one with SLOT(...) surrounding it). This may be a compiler-specific constructor order error.

    This is my basic code:
    Qt Code:
    1. #include <QtCore\QObject>
    2. #include <QtNetwork\QTcpSocket>
    3. #include <QtCore\QDebug>
    4.  
    5. class my_TCP_socket : public QObject
    6. {
    7. public:
    8. explicit my_TCP_socket(QObject *parent = 0);
    9.  
    10. ~my_TCP_socket();
    11.  
    12. private:
    13. QTcpSocket *m_socket_ptr;
    14.  
    15. void read_it();
    16. };
    17.  
    18.  
    19.  
    20. my_TCP_socket::my_TCP_socket(QObject *parent) :
    21. QObject(parent)
    22. {
    23. m_socket_ptr = new QTcpSocket(this);
    24.  
    25. m_socket_ptr->connectToHost("10.10.10.126", 5);
    26. if (!(m_socket_ptr->waitForConnected(5000)))
    27. {
    28. qDebug() << "Not connected!";
    29. m_socket_ptr = NULL;
    30. }
    31. else
    32. {
    33. qDebug() << "Connected!";
    34. }
    35.  
    36. this->connect(m_socket_ptr, SIGNAL(readyRead()), this, SLOT(this->read_it(void)));
    37. }
    38.  
    39. void my_TCP_socket::read_it()
    40. {
    41. QDataStream in(m_socket_ptr);
    42.  
    43. qint64 bytes_available = m_socket_ptr->bytesAvailable();
    44. if (bytes_available > 0)
    45. {
    46. QString in_data;
    47. in >> in_data;
    48.  
    49. qDebug() << in_data;
    50. }
    51. else
    52. {
    53. qDebug() << "no data";
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 

    Those functions may not exist yet when "connect(...)" is called in the constructor, although I may just be doing it wrong because this

    Qt Code:
    1. int method_index = this->metaObject()->indexOfMethod("init()");
    To copy to clipboard, switch view to plain text mode 

    just returns -1, and that's after initialization.

    Again, any feedback would be helpful.


    Added after 20 minutes:


    Followup: Should have noted that the attempt connect the "read_it()" function resulted in this error at runtime:
    Qt Code:
    1. Object::connect: No such slot QObject::this->read_it(void) in *path redacted*
    To copy to clipboard, switch view to plain text mode 

    I have tentatively discovered that the Q_OBJECT macro needs to be declared at the top of the "private" section of the class, but that is producing a linker error. I put that into a new thread. The question seemed different enough from this thread.

    Please advise still. The examples are not working outside QtCreator.
    Last edited by amdreallyfast; 24th May 2014 at 23:29.

Similar Threads

  1. Replies: 1
    Last Post: 15th September 2013, 08:49
  2. error "cmd.exe" exited with code 1 in visual studio 2010
    By cactus0830 in forum Installation and Deployment
    Replies: 1
    Last Post: 22nd June 2013, 04:25
  3. Replies: 1
    Last Post: 14th May 2011, 08:02
  4. Replies: 1
    Last Post: 10th March 2011, 14:40
  5. Qmake DLLDESTDIR, Visual Studio "clean solution"
    By SiLiZiUMM in forum Installation and Deployment
    Replies: 4
    Last Post: 18th March 2008, 12:14

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.