New error in Qt
Unsolved
Qt 6
-
My client was working perfectly fine but now when I run it after 6 days it is giving me an error:
moc_tsocket.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl Tsocket::sendmessage(class QString,int)" (?sendmessage@Tsocket@@AEAAXVQString@@H@Z) referenced in function "public: virtual int __cdecl Tsocket::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Tsocket@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
The code for tcpsocket file is:
#include "tsocket.h" #include"mainwindow.h" Tsocket::Tsocket() { connect(this, SIGNAL(connected()), this, SLOT(connected())); connect(this, SIGNAL(readyRead()), this, SLOT(readdata())); connect(this, SIGNAL(disconnected()), this, SLOT(disconnect_ser())); } Tsocket::~Tsocket() { } QString Tsocket::configure(QString str_start,QString str_end,QString msg, QString replace_val) { std::string str = str_start.toLocal8Bit().constData(); std::string string_end = str_end.toLocal8Bit().constData(); std::string replace_val1 = replace_val.toLocal8Bit().constData(); std::string msg1 = msg.toLocal8Bit().constData(); std::size_t str_size=str.length(); std::string final_str=""; std::string str3; while(true){ std::size_t pos1=msg1.std::string::find(str); if(pos1==std::string::npos){ break; } std::string str1=msg1.std::string::substr(0,pos1+str_size); //msg1.find std::size_t pos2=msg1.std::string::find(string_end); std::string str2=msg1.std::string::substr(pos2); std::string str_copy=msg1.std::string::substr(pos2+str_size+1); str1+=replace_val1+str2; pos2=str1.std::string::find(string_end); str3=str1.std::string::substr(0,pos2+str_size+1); msg1=str_copy; final_str+=""+str3; } final_str+=""+msg1; QString qstr = QString::fromStdString(final_str); return qstr; } const std::string Tsocket::settime() { time_t now = time(0); struct tm tstruct; char buf[80]; tstruct = *localtime(&now); strftime(buf, sizeof(buf), "%Y-%m-%dTO%XZ", &tstruct); return buf; } void Tsocket::sendmessage(QString data,int cnt) { QString str[2]={"<TranCode>","<CreDtTm>"}; QString str_end[2]={"</TranCode>","</CreDtTm>"}; std::string timestamp=settime(); QString qstr = QString::fromStdString(timestamp); QString rep_val[3]={ QString::number(cnt),qstr}; QString send_str; for(int i=0;i<2;i++){ send_str=configure(str[i],str_end[i],data,rep_val[i]); data=send_str; } QByteArray br = data.toUtf8(); this->write(br); } void Tsocket::readdata() { QByteArray data = this->readAll(); emit rec_slot(data); } void Tsocket::disconnect_ser() { emit gotNewMessage( QString("%1") .arg("disconnected from server:") ); this->deleteLater(); } void Tsocket::connected(){ emit gotNewMessage(QString("%1") .arg("client connected")); }
Can anyone tell me reason for this error ?
-
Hi,
Did you add/remove the Q_OBJECT macro from your class declaration ?
Is this a slot ?