can not call function of different class
-
-
@JadeN001
As @jsulm has just said, learning to use a debugger will in the long-run be the best time you spent! Just do it soon.In the meantime, in
on_pushButton_send_clicked()just before you try to callmw->send_MsgToServer(send);I'd put in some moreqDebug()statements which show some of the properties of yourconnectionobject viamw->.... You're looking to just verify thatmwis indeed still pointing at some validconnection, just in case..... -
@JadeN001
As @jsulm has just said, learning to use a debugger will in the long-run be the best time you spent! Just do it soon.In the meantime, in
on_pushButton_send_clicked()just before you try to callmw->send_MsgToServer(send);I'd put in some moreqDebug()statements which show some of the properties of yourconnectionobject viamw->.... You're looking to just verify thatmwis indeed still pointing at some validconnection, just in case.....@JonB @jsulm yeah I really appreciate your suggestion. I will start.
I have checked Value of object "mw" by qDebug(). and It returns proper object value.
something like this :object : connection(0x201c0350, name="connection")I thought that might be the issue is ,the object was not being generated properly.But i was wrong.
-
@JonB @jsulm yeah I really appreciate your suggestion. I will start.
I have checked Value of object "mw" by qDebug(). and It returns proper object value.
something like this :object : connection(0x201c0350, name="connection")I thought that might be the issue is ,the object was not being generated properly.But i was wrong.
@JadeN001
Assuming it really is as you say, and you really have rebuilt your code etc., and you are compiling for/viewing debug, and it's not crashing, it's going to be pretty hard to answer how the linemw->send_MsgToServer(send)could simply "not get executed", without a debugger....One last thing I can think of, just in case. Your first line in
send_MsgToServer()is:qDebug()<<"in sendmsgserver"<<m_pclientsocket;Just in case there's some problem serializing
m_pclientsocket, temporarily change it to plain:qDebug()<<"in sendmsgserver"(I don't think there actually will have been an issue because I think you're only trying to print out the pointer here, but it's worth a try...)
-
@JadeN001
Assuming it really is as you say, and you really have rebuilt your code etc., and you are compiling for/viewing debug, and it's not crashing, it's going to be pretty hard to answer how the linemw->send_MsgToServer(send)could simply "not get executed", without a debugger....One last thing I can think of, just in case. Your first line in
send_MsgToServer()is:qDebug()<<"in sendmsgserver"<<m_pclientsocket;Just in case there's some problem serializing
m_pclientsocket, temporarily change it to plain:qDebug()<<"in sendmsgserver"(I don't think there actually will have been an issue because I think you're only trying to print out the pointer here, but it's worth a try...)
-
I have define m_pClientsocket in constructor of class
but it failed to access in send_MsgToServer().
because ,If I define in constuctor then when formclient class define the object on connection classFormClient::FormClient(QString name, QWidget *parent) : QWidget(parent), ui(new Ui::FormClient) { ui->setupUi(this); delegate=new mydelegate(this); mw=new connection(this); }At that time value of socket is getting changed.
So the changes it bu moving them_pclientsocket= new QTcpSocket(this);in to another main function.
void connection::on_pushButton_connect_clicked() { m_pclientsocket= new QTcpSocket(this); ui->textEdit_Sendname->clear(); m_pclientsocket->connectToHost(ui->textEdit_IP->toPlainText(),quint16(ui->textEdit_Port->toPlainText().toInt())); if(m_pclientsocket->waitForConnected(1000)){ qDebug()<<"connected"<<m_pclientsocket; ui->label_connection->setText("Connected to Server"); } }send_MsgToServer() can not access it . where i am wrong.? what could be solution?
-
In send_MsgToServer(). the ans of
void connection::send_MsgToServer(QString msg) { qDebug()<<"in sendmsgserver"<<m_pclientsocket; m_pclientsocket->write(msg.toStdString().c_str()); qDebug()<<"message sended "<<msg; }in sendmsgserver QApplication(0x22fe28) QIODevice::write (QApplication): device not openwhat it is indicating? How can be value of socket be like QApplication.
-
Hi,
Why are you creating a new
QTcpSocketeach time you callon_pushButton_connect_clicked? -
Hi,
Why are you creating a new
QTcpSocketeach time you callon_pushButton_connect_clicked?And why are you using
waitForConnected?this cannot work. use signals&slots!
regards
-
Hi,
Why are you creating a new
QTcpSocketeach time you callon_pushButton_connect_clicked?@SGaist because the Problem i am facing :
if I called new QTcpSocket from constructor,thenFormClient::FormClient(QString name, QWidget *parent) : QWidget(parent), ui(new Ui::FormClient) { ui->setupUi(this); delegate=new mydelegate(this); mw=new connection(this); }this class create QTcpSocket evety time when mw=new connection(this); called.
because of that the void connection::send_MsgToServer(QString msg)
get different value of QTcpsocket. -
Currently, with the code you provided, it seems you already have an architectural problem.
Can you describe what you are exactly trying to build ?
-
Currently, with the code you provided, it seems you already have an architectural problem.
Can you describe what you are exactly trying to build ?
@SGaist I am creating one QTableview on clientside.when ever client connected,one editor for chatting will create in that tableview.

If want to send message to John from this editor.but when i send message from particular editor the value of QtcpSocket i am getting is somthing like this "
in sendmsgserver QApplication(0x22fe28) QIODevice::write (QApplication): device not openconnection.cpp is class where socket is created.
formclient.cpp is class of widgets of chatting.