Document WebSocket::sendTextMessage(string message)
[contrib/qtwebsockets.git] / src / imports / qmlwebsockets / qqmlwebsocket.cpp
index 94d20e0..d165260 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Kurt Pattyn <pattyn.kurt@gmail.com>.
 ** Contact: http://www.qt-project.org/legal
 **
 ** This file is part of the QtWebSockets module of the Qt Toolkit.
     \instantiates QQmlWebSocket
 
     \inqmlmodule Qt.WebSockets
+    \ingroup websockets-qml
     \brief QML interface to QWebSocket.
 
-    WebSockets is a web technology providing full-duplex communications channels over a single TCP connection.
-    The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011 (see http://tools.ietf.org/html/rfc6455).
+    WebSockets is a web technology providing full-duplex communications channels over a
+    single TCP connection.
+    The WebSocket protocol was standardized by the IETF as
+    \l {http://tools.ietf.org/html/rfc6455} {RFC 6455} in 2011.
 */
 
 /*!
   \qmlproperty QUrl WebSocket::url
-  Server url to connect to. The url must have one of 2 schemes: {ws://} or {wss://}.
-  When not supplied, then {ws://} is used.
+  Server url to connect to. The url must have one of 2 schemes: \e ws:// or \e wss://.
+  When not supplied, then \e ws:// is used.
   */
 
 /*!
   \sa WebSocket::status
   */
 
+/*!
+  \qmlmethod void WebSocket::sendTextMessage(string message)
+  Sends \c message to the server.
+  */
+
 #include "qqmlwebsocket.h"
 #include <QtWebSockets/QWebSocket>
 
@@ -119,11 +127,11 @@ QQmlWebSocket::~QQmlWebSocket()
 qint64 QQmlWebSocket::sendTextMessage(const QString &message)
 {
     if (m_status != Open) {
-        setErrorString(tr("Messages can only be send when the socket has Open status."));
+        setErrorString(tr("Messages can only be sent when the socket is open."));
         setStatus(Error);
         return 0;
     }
-    return m_webSocket->write(message);
+    return m_webSocket->sendTextMessage(message);
 }
 
 QUrl QQmlWebSocket::url() const
@@ -167,9 +175,13 @@ void QQmlWebSocket::componentComplete()
 {
     m_webSocket.reset(new (std::nothrow) QWebSocket());
     if (Q_LIKELY(m_webSocket)) {
-        connect(m_webSocket.data(), SIGNAL(textMessageReceived(QString)), this, SIGNAL(textMessageReceived(QString)));
-        connect(m_webSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(onError(QAbstractSocket::SocketError)));
-        connect(m_webSocket.data(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(onStateChanged(QAbstractSocket::SocketState)));
+        connect(m_webSocket.data(), &QWebSocket::textMessageReceived,
+                this, &QQmlWebSocket::textMessageReceived);
+        typedef void (QWebSocket::* ErrorSignal)(QAbstractSocket::SocketError);
+        connect(m_webSocket.data(), static_cast<ErrorSignal>(&QWebSocket::error),
+                this, &QQmlWebSocket::onError);
+        connect(m_webSocket.data(), &QWebSocket::stateChanged,
+                this, &QQmlWebSocket::onStateChanged);
 
         m_componentCompleted = true;