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

How to use QStringList

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 673 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.
  • E Offline
    E Offline
    ELIF
    wrote on last edited by
    #1

    I have a function in QT I want to write each of list member seperately.Like this

    elif
    23
    15.06.97

    void MainWindow::Splt(){
        QString myString = " elif ,23, 15.06.97,  ";
       QStringList list1 = myString.split(QLatin1Char(','));
      //qDebug()<<list1;
    }
    

    I have an error

    error: no match for ‘operator<<’ (operand types are ‘<unresolved overloaded function type>’ and ‘QString’)
         qDebug<<list1.first();
               ^
    

    How to solve it ,thank you.

    JonBJ 1 Reply Last reply
    0
    • E ELIF

      I have a function in QT I want to write each of list member seperately.Like this

      elif
      23
      15.06.97

      void MainWindow::Splt(){
          QString myString = " elif ,23, 15.06.97,  ";
         QStringList list1 = myString.split(QLatin1Char(','));
        //qDebug()<<list1;
      }
      

      I have an error

      error: no match for ‘operator<<’ (operand types are ‘<unresolved overloaded function type>’ and ‘QString’)
           qDebug<<list1.first();
                 ^
      

      How to solve it ,thank you.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @ELIF
      As per your commented-out line, you intended qDebug() << ... not qDebug << ....

      1 Reply Last reply
      3
      • E Offline
        E Offline
        ELIF
        wrote on last edited by
        #3

        I get the correct values from TCP IP protocol. But I need seperate them from each other.In while loop I just want to add \n actually,but I cant.
        My result is 0x010x0230OK!OX2F.
        My aiming result is 0x01
        0x02
        30
        OK!
        OX2F

        void Client::sendMessageToServer(){ 
            QByteArray baData;
            baData.fill(0, 80);
            QString x="void Client::sendMessageToServer(){ 
            qDebug() << "INSIDe sendMessageToServer"
                qDebug() << tcpSocket->canReadLine() << tcpSocket->readAll();
                QByteArray baData;
                baData.fill(0, 80);
                QString x="0x01,0x02,30, OK! ,OX2F";
                QStringList list1 = x.split(QLatin1Char(','));
                int k=list1.size()-1;
            
                while(k>=0){
                   baData.insert(0, list1.at(k));
                   k--;
                }
            
                baData.resize(80);
                tcpSocket->write(baData);
            }
            
        
        
        J.HilkJ 1 Reply Last reply
        0
        • E ELIF

          I get the correct values from TCP IP protocol. But I need seperate them from each other.In while loop I just want to add \n actually,but I cant.
          My result is 0x010x0230OK!OX2F.
          My aiming result is 0x01
          0x02
          30
          OK!
          OX2F

          void Client::sendMessageToServer(){ 
              QByteArray baData;
              baData.fill(0, 80);
              QString x="void Client::sendMessageToServer(){ 
              qDebug() << "INSIDe sendMessageToServer"
                  qDebug() << tcpSocket->canReadLine() << tcpSocket->readAll();
                  QByteArray baData;
                  baData.fill(0, 80);
                  QString x="0x01,0x02,30, OK! ,OX2F";
                  QStringList list1 = x.split(QLatin1Char(','));
                  int k=list1.size()-1;
              
                  while(k>=0){
                     baData.insert(0, list1.at(k));
                     k--;
                  }
              
                  baData.resize(80);
                  tcpSocket->write(baData);
              }
              
          
          
          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by J.Hilk
          #4

          @ELIF why don't you replace

          QStringList list1 = myString.split(QLatin1Char(','));
          

          with

          QStringList list1 = myString.replace(",", "\n");

          myString.replace(",", "\n");
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ELIF
            wrote on last edited by
            #5

            @J-Hilk said in How to use QStringList:

            myString

            its so sense I think,when I try it,
            if i write qDebug()<<list1;
            ı get error

            J.HilkJ 1 Reply Last reply
            0
            • E ELIF

              @J-Hilk said in How to use QStringList:

              myString

              its so sense I think,when I try it,
              if i write qDebug()<<list1;
              ı get error

              J.HilkJ Online
              J.HilkJ Online
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @ELIF my bad,

              replace returns a QString, not a QStringList.

              in fact, it actually modifies the original string, so writing only:

              myString.replace(",", "\n");
              
              

              should be fine.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • E Offline
                E Offline
                ELIF
                wrote on last edited by ELIF
                #7

                @J-Hilk said in How to use QStringList:

                yString.replace(",", "\n");

                void Client::sendMessageToServer(){ //bu gönderileceleri tek tek ayırmalısın
                    qDebug() << "INSIDe sendMessageToServer";
                    qDebug() << tcpSocket->canReadLine() << tcpSocket->readAll();
                    QByteArray baData;
                    baData.fill(0, 80);
                    QString x="0x01,0x02,30,OK!,OX2F";
                    QString list1 = x.replace("," , "\n");
                
                    baData.insert(0, list1);
                
                    qDebug()<<list1;
                    baData.resize(80);
                    tcpSocket->write(baData);
                }
                

                I get only 0x01 I should get all of them.

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  ELIF
                  wrote on last edited by
                  #8

                  OK I solved it I canged readLine with readAll then I get the whole message.
                  I apprecite your answers thank you.::)
                  this->ui->textEdit_6->setText(clientConnection->readAll());

                  1 Reply Last reply
                  1

                  • Login

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