Can't write in a dialog
-
I have one classA with its GUI form , another class ClassB with its own GUI form and when I try to send text from ClassA to ClassB's GUI , I'm getting this message.
I had QHBoxLayout , which was holding a QTextEdit and a QPushButton.
So when I click that button , text from that QTextEdit should be written.QIODevice::write (QTextEdit, "SendtextEdit"): ReadOnly device //'SendtextEdit' is the name of QTextEdit
so out of nowhere I came with the solution of removing the QHBoxLayout and after that Idea....I've got another error message
QIODevice::write (QWidget, "qt_scrollarea_hcontainer"): ReadOnly device
so whats happening here ?
-
I have one classA with its GUI form , another class ClassB with its own GUI form and when I try to send text from ClassA to ClassB's GUI , I'm getting this message.
I had QHBoxLayout , which was holding a QTextEdit and a QPushButton.
So when I click that button , text from that QTextEdit should be written.QIODevice::write (QTextEdit, "SendtextEdit"): ReadOnly device //'SendtextEdit' is the name of QTextEdit
so out of nowhere I came with the solution of removing the QHBoxLayout and after that Idea....I've got another error message
QIODevice::write (QWidget, "qt_scrollarea_hcontainer"): ReadOnly device
so whats happening here ?
@hjohn QIODevice::write?! Can you please show the code? It is really unclear what you're doing. To exchange data between different UI classes you should either use signals/slots or public methods.
" text from that QTextEdit should be written" - written to where? Into a file? -
@hjohn QIODevice::write?! Can you please show the code? It is really unclear what you're doing. To exchange data between different UI classes you should either use signals/slots or public methods.
" text from that QTextEdit should be written" - written to where? Into a file?@jsulm
I am trying to build a client server chat
server is all set, But now in client ...I have three classes
1. class clientMainForm : public QDialog
2.class clientWidget : public QWidget
3.class myDelegate : public QStyledItemDelegateno 1. creates QTcpSocket and all its connections with signals and slots. It has main GUI which handles the client , meaning the main gui of the current client.
no 2. Its a widget (GUI form ) for the clients that are connected , other than the current client.
no3. is Delegate class in which
QWidgetcreateEditor(QWidget parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
method has been implemented to create clientWidget as an editor. Delegate class is called in clientMainForm .
thats clientWidget 's gui. which gets open in clientMainForm's GUI. when we click on OK button , that message should go to the other client through server ...thats the main task here.
I have used signals and slots to make all the connections and the all are working fine but when it comes for QTcpSocket::write(message.tostdstring().c_str()); it displays the message mentioned at the beginning of the thread.So in conclusion , the question is , How can we make this editor which was created by using QStyledItemDelegate ,work like any other GUI ?
-
@hjohn said in Can't write in a dialog:
QIODevice::write (QTextEdit, "SendtextEdit"):
That looks really odd.
do you mean
write (QTextEdit->text());please show the actual real code.
-
@hjohn said in Can't write in a dialog:
QIODevice::write (QTextEdit, "SendtextEdit"):
That looks really odd.
do you mean
write (QTextEdit->text());please show the actual real code.
@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.
-
@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.
This post is deleted! -
@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.
-
@hjohn It's not clear where m_clientSocket is created/comming from and where it is actually connected.
@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 ?
-
Hi,
Are you trying to implement something like Qt's network chat example ?
-
@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())); } -
So you want to have several "chat windows" in your QListView that all send to the same 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.