error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp
-
@Pl45m4 this a a example with their code. It's run good. But my project is failed.
void MainWindow::SendBtnClicked() { QLineEdit* messageEdit = this->findChild<QLineEdit*>("messageEdit"); QString text = messageEdit->text(); if(text.length()>0) { QByteArray bytes = text.toUtf8(); std::string msg(bytes.data(),bytes.length()); _io->socket()->emit("new message",msg); text.append(" : You"); QListWidgetItem *item = new QListWidgetItem(text); item->setTextAlignment(Qt::AlignRight); Q_EMIT RequestAddListItem(item); messageEdit->clear(); } }
_io->socket()->emit("new message",msg);
@HoaiNam10TH said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
this a a example with their code.
Their code? Whose code is this?
_io->socket()->emit("new message",msg);
There could be a function called
emit()
which has nothing to do with Qt, but sets up a connection or something else...
Using theemit
(fromQObject
) in a way like this should never work.If you really want to emit the signal in
_io->socket
, then use what @J-Hilk suggested and what I wrote here@Pl45m4 said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
_io->socket()->joinConversation(userId);
If possible show how
_io->socket()->emit("new message",msg);
is defined... -
@HoaiNam10TH said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
this a a example with their code.
Their code? Whose code is this?
_io->socket()->emit("new message",msg);
There could be a function called
emit()
which has nothing to do with Qt, but sets up a connection or something else...
Using theemit
(fromQObject
) in a way like this should never work.If you really want to emit the signal in
_io->socket
, then use what @J-Hilk suggested and what I wrote here@Pl45m4 said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
_io->socket()->joinConversation(userId);
If possible show how
_io->socket()->emit("new message",msg);
is defined...@Pl45m4 Follow this github page, it has an example of socket.io with cpp (examples folder). Their project runs fine on my machine:
_io->socket()->emit("new message",msg);
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt. -
@Pl45m4 Follow this github page, it has an example of socket.io with cpp (examples folder). Their project runs fine on my machine:
_io->socket()->emit("new message",msg);
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt.@HoaiNam10TH said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt.
Then this is the problem/cause of the error message. Like I said earlier, Qt header files go
#define emit
Just like that. That will make your
_io->socket()->emit("new message",msg);
become_io->socket()->("new message",msg);
and henceerror: expected unqualified-id before ‘(’ token
.Do not include Qt header files before the
_io->socket()->emit("new message",msg);
line. If you cannot do that you may be able to go#undef emit
around that_io->socket()->emit(...)
line. -
@HoaiNam10TH said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt.
Then this is the problem/cause of the error message. Like I said earlier, Qt header files go
#define emit
Just like that. That will make your
_io->socket()->emit("new message",msg);
become_io->socket()->("new message",msg);
and henceerror: expected unqualified-id before ‘(’ token
.Do not include Qt header files before the
_io->socket()->emit("new message",msg);
line. If you cannot do that you may be able to go#undef emit
around that_io->socket()->emit(...)
line.@JonB Or use QT_NO_KEYWORDS :)
-
@JonB Or use QT_NO_KEYWORDS :)
@Christian-Ehrlicher
Indeed, but if your own code being compiled is usingemit
before Qt signals you still have to deal with that. One way or the other it needs sorting. -
@Christian-Ehrlicher
Indeed, but if your own code being compiled is usingemit
before Qt signals you still have to deal with that. One way or the other it needs sorting.@JonB said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
but if your own code being compiled is using emit before Qt signals you still have to deal with that
Yes, either remove it or use Q_EMIT instead.
-
@JonB said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
but if your own code being compiled is using emit before Qt signals you still have to deal with that
Yes, either remove it or use Q_EMIT instead.
@Christian-Ehrlicher Ah. putting
Q_EMIT
instead ofemit
sounds like I good idea. Does Qt source do this? -
@Christian-Ehrlicher Ah. putting
Q_EMIT
instead ofemit
sounds like I good idea. Does Qt source do this?@JonB said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
Does Qt source do this?
Qt source code does not use 'signals' or 'slots' or 'emit' in public headers - only the Q_foo keywords.
-
@Pl45m4 Follow this github page, it has an example of socket.io with cpp (examples folder). Their project runs fine on my machine:
_io->socket()->emit("new message",msg);
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt.@HoaiNam10TH said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
@Pl45m4 Follow this github page, it has an example of socket.io with cpp (examples folder). Their project runs fine on my machine:
_io->socket()->emit("new message",msg);
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt.Hi,
The Qt example in the repository you link contains a README that explains that you need the no_keyword configuration option and why.
-
@HoaiNam10TH said in error: expected unqualified-id before ‘(’ token when using emit event of socket.io-client-cpp:
@Pl45m4 Follow this github page, it has an example of socket.io with cpp (examples folder). Their project runs fine on my machine:
_io->socket()->emit("new message",msg);
emit("new message",msg) it is a function (owned by socket.io-client-cpp) to invoke method on nodejs server. It is not emit of Qt.Hi,
The Qt example in the repository you link contains a README that explains that you need the no_keyword configuration option and why.
@SGaist
That's right. Thanks everyone -
S SGaist has marked this topic as solved on