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
Forum Updated to NodeBB v4.3 + New Features

Can't write in a dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 2.2k Views 2 Watching
  • 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 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