Qt World Summit: Submit your Presentation

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 ?

  • Lifetime Qt Champion

    @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 QStyledItemDelegate

    no 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 ?

  • Lifetime Qt Champion

    @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 QDialog

    void clientMainForm ::clientListArrived(QString ID)
         myDelegate *delegate=new myDelegate (ID);
         clientWidget *form=new clientWidget ();
         QStandardItem*item=new QStandardItem;
         QStandardItemModel *model=new QStandardItemModel;
         const QModelIndex index=model->index(count,0,QModelIndex());
    void clientMainForm ::sendMessage(QString message)

    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.

    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.

  • Lifetime Qt Champion

    This post is deleted!

  • Lifetime Qt Champion

    @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,

     QTcpSocket *m_clientSocket;


    void clientMainForm::on_btnConnect_clicked()
        m_clientSocket=new QTcpSocket(this);
           qDebug()<<"Client Connected";

  • Lifetime Qt Champion


    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.

  • Lifetime Qt Champion

    @hjohn Did you make sure that your m_clientSocket is actually connected?

  • @jsulm Yes, It's connected and working properly.
    The problem arises when I try to send message from the editor.

  • Lifetime Qt Champion

    So you want to have several "chat windows" in your QListView that all send to the same server ?

  • @SGaist Yes.
    I have a QListView and QWidgetcreateEditor()* has put those chat windows in that ListView.

  • Lifetime Qt Champion

    And each of these chat window would handle its socket itself ?

  • @SGaist yes probably
    the widget should recognize the socket .

  • Lifetime Qt Champion

    Then it looks like the Fortune Client example might be a better base.

Log in to reply