Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't write in a dialog
QtWS25 Last Chance

Can't write in a dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hjohn
    wrote on last edited by hjohn
    #1

    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 ?

    jsulmJ 1 Reply Last reply
    0
    • H hjohn

      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 ?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

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

      H 1 Reply Last reply
      4
      • jsulmJ jsulm

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

        H Offline
        H Offline
        hjohn
        wrote on last edited by hjohn
        #3

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

        0_1530340654316_widget_form.jpg

        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 ?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          H 1 Reply Last reply
          4
          • mrjjM mrjj

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

            H Offline
            H Offline
            hjohn
            wrote on last edited by hjohn
            #5

            @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 ();
                 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.

            jsulmJ 2 Replies Last reply
            0
            • H hjohn

              @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 ();
                   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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • H hjohn

                @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 ();
                     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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @hjohn It's not clear where m_clientSocket is created/comming from and where it is actually connected.

                H 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @hjohn It's not clear where m_clientSocket is created/comming from and where it is actually connected.

                  H Offline
                  H Offline
                  hjohn
                  wrote on last edited by hjohn
                  #8

                  @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()));
                  
                  }
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    Are you trying to implement something like Qt's network chat example ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Hi,

                      Are you trying to implement something like Qt's network chat example ?

                      H Offline
                      H Offline
                      hjohn
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • H hjohn

                        @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()));
                        
                        }
                        
                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

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

                        H 1 Reply Last reply
                        0
                        • jsulmJ jsulm

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

                          H Offline
                          H Offline
                          hjohn
                          wrote on last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

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

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            H 1 Reply Last reply
                            0
                            • SGaistS SGaist

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

                              H Offline
                              H Offline
                              hjohn
                              wrote on last edited by
                              #14

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

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

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

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                H 1 Reply Last reply
                                0
                                • SGaistS SGaist

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

                                  H Offline
                                  H Offline
                                  hjohn
                                  wrote on last edited by
                                  #16

                                  @SGaist yes probably
                                  the widget should recognize the socket .

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

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

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved