Can't write in a dialog
-
@mrjj thank you very much for responding
1. class clientMainForm : public QDialogvoid clientMainForm ::clientListArrived(QString ID) { myDelegate *delegate=new myDelegate (ID); clientWidget *form=new clientWidget (); ui->listView->setItemDelegate(delegate); QStandardItem*item=new QStandardItem; QStandardItemModel *model=new QStandardItemModel; model->setItem(count,item); const QModelIndex index=model->index(count,0,QModelIndex()); count++; ui->listView->openPersistentEditor(index); } void clientMainForm ::sendMessage(QString message) { if(!message.isEmpty()){ if(m_clientSocket->write(message.tostdString().c_str())){ ui->senderTxt->clear(); ui->senderTxt->setFocus(); } } }
2.class clientWidget : public QWidget // ui of this class , you'll find in previous post
void clientWidget ::on_pushButton_clicked() { QString message=":"+ui->SendtextEdit->toPlainText().trimmed(); emit privateMessage(message); //this signal is connected to the clientMainForm ::sendMessage(QString message) slot. ui->textEdit->append(message); }
3.class myDelegate : public QStyledItemDelegate
QWidget*myDelegate ::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{ clientWidget *editor=new clientWidget (parent); return editor; }
whenever a new client arrives , QStrign ID is given to that client and after that void clientMainForm ::clientListArrived(QString ID ) is called.
-
@jsulm its in class clientMainForm : public QDialog
As I have mentioned earlier , everything about QTcpSocket is done in clientMainForm class using signals and slots.
in clientMainForm.h,public: QTcpSocket *m_clientSocket;
clientMainForm.cpp
void clientMainForm::on_btnConnect_clicked() { m_clientSocket=new QTcpSocket(this); m_clientSocket->connectToHost(ui->IPText->toPlainText(),qint16(ui->PortTxt->toPlainText().toInt())); if(m_clientSocket->waitForConnected(1000)){ qDebug()<<"Client Connected"; } connect(m_clientSocket,SIGNAL(readyRead()),this,SLOT(ReceiveData())); connect(m_clientSocket,SIGNAL(disconnected()),this,SLOT(connectionLost())); }
-
Hi,
Are you trying to implement something like Qt's network chat example ?
-
@SGaist not exactly the same
What I'm trying here is , I have a QListView in which , by using QWidget createEditor();* multiple creators(the image iploaded in earlier post) are created . I want to send the text written in that editor to server. -
So you want to have several "chat windows" in your QListView that all send to the same server ?
-
And each of these chat window would handle its socket itself ?
-
Then it looks like the Fortune Client example might be a better base.