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

Problem with QStringList

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.4k 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.
  • D Offline
    D Offline
    DRoscoe
    wrote on last edited by
    #1

    Consider the following:

      // create the message log header
      std::ostringstream out;
      out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
          << std::endl
          << "<TapMessagingLog start_time=\"" << ACE_OS::gettimeofday().sec()
          << "\">" << std::endl;
    
      if (remote_logging)
      {
        // we can't log messages until we have a connection to the service, so
        // pend the header message for now
        pending_msglog_messages.push_back(QString::fromStdString(out.str()));
      }
    

    Then later...

    void TapDisplaySingleton::unwindMsgLogMessages()
    {
      //DAR_DEBUG
      QString test = "abcdefg";
      pending_msglog_messages.push_back(test);
      QString test2 = pending_msglog_messages.at(1);
      //DAR_DEBUG
    
      while(!pending_msglog_messages.isEmpty())
      {
        QString out_str = pending_event_log_messages.takeFirst();
    

    When I try to pull item 0 from the QStringList, the code throws an assertion, but in my debug code, I create a simple string, push it onto the QStringList and pull it off again, and it works fine. It clearly does not play nicely with the first string, but I've never had any problems working with it before trying to put it into a QStringList

    Any ideas?

    jsulmJ kshegunovK 2 Replies Last reply
    0
    • D DRoscoe

      Consider the following:

        // create the message log header
        std::ostringstream out;
        out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
            << std::endl
            << "<TapMessagingLog start_time=\"" << ACE_OS::gettimeofday().sec()
            << "\">" << std::endl;
      
        if (remote_logging)
        {
          // we can't log messages until we have a connection to the service, so
          // pend the header message for now
          pending_msglog_messages.push_back(QString::fromStdString(out.str()));
        }
      

      Then later...

      void TapDisplaySingleton::unwindMsgLogMessages()
      {
        //DAR_DEBUG
        QString test = "abcdefg";
        pending_msglog_messages.push_back(test);
        QString test2 = pending_msglog_messages.at(1);
        //DAR_DEBUG
      
        while(!pending_msglog_messages.isEmpty())
        {
          QString out_str = pending_event_log_messages.takeFirst();
      

      When I try to pull item 0 from the QStringList, the code throws an assertion, but in my debug code, I create a simple string, push it onto the QStringList and pull it off again, and it works fine. It clearly does not play nicely with the first string, but I've never had any problems working with it before trying to put it into a QStringList

      Any ideas?

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

      @DRoscoe

      It is not really clear where the assertion is thrown and you didn't say which assertion.
      Is it here:

      pending_msglog_messages.push_back(test);
      QString test2 = pending_msglog_messages.at(1);
      

      ?
      If so, then it could be that pending_msglog_messages contains only one element and you try to access the second calling at(1).
      Shouldn't it be

      QString test2 = pending_msglog_messages.at(0);
      

      You can print the number of elements in the list to see how many elements it contains.
      ?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • D DRoscoe

        Consider the following:

          // create the message log header
          std::ostringstream out;
          out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
              << std::endl
              << "<TapMessagingLog start_time=\"" << ACE_OS::gettimeofday().sec()
              << "\">" << std::endl;
        
          if (remote_logging)
          {
            // we can't log messages until we have a connection to the service, so
            // pend the header message for now
            pending_msglog_messages.push_back(QString::fromStdString(out.str()));
          }
        

        Then later...

        void TapDisplaySingleton::unwindMsgLogMessages()
        {
          //DAR_DEBUG
          QString test = "abcdefg";
          pending_msglog_messages.push_back(test);
          QString test2 = pending_msglog_messages.at(1);
          //DAR_DEBUG
        
          while(!pending_msglog_messages.isEmpty())
          {
            QString out_str = pending_event_log_messages.takeFirst();
        

        When I try to pull item 0 from the QStringList, the code throws an assertion, but in my debug code, I create a simple string, push it onto the QStringList and pull it off again, and it works fine. It clearly does not play nicely with the first string, but I've never had any problems working with it before trying to put it into a QStringList

        Any ideas?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        @DRoscoe said in Problem with QStringList:

        while(!pending_msglog_messages.isEmpty())
        {
           QString out_str = pending_event_log_messages.takeFirst();
        

        A typo? I'd expect the condition to be !pending_event_log_messages.isEmpty(). It appears you're judging for the availability of items in one list/vector by the elements in another, and if for some reason there's a mismatch ...

        Read and abide by the Qt Code of Conduct

        jsulmJ D 2 Replies Last reply
        5
        • kshegunovK kshegunov

          @DRoscoe said in Problem with QStringList:

          while(!pending_msglog_messages.isEmpty())
          {
             QString out_str = pending_event_log_messages.takeFirst();
          

          A typo? I'd expect the condition to be !pending_event_log_messages.isEmpty(). It appears you're judging for the availability of items in one list/vector by the elements in another, and if for some reason there's a mismatch ...

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

          @kshegunov That's what code reviews are good for: more eyes see more :-)

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • kshegunovK kshegunov

            @DRoscoe said in Problem with QStringList:

            while(!pending_msglog_messages.isEmpty())
            {
               QString out_str = pending_event_log_messages.takeFirst();
            

            A typo? I'd expect the condition to be !pending_event_log_messages.isEmpty(). It appears you're judging for the availability of items in one list/vector by the elements in another, and if for some reason there's a mismatch ...

            D Offline
            D Offline
            DRoscoe
            wrote on last edited by
            #5

            @kshegunov Oh dear God.. I got code blind! Copy and paste error.

            Thanks!

            kshegunovK mrjjM 2 Replies Last reply
            2
            • D DRoscoe

              @kshegunov Oh dear God.. I got code blind! Copy and paste error.

              Thanks!

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @DRoscoe
              No hassle, it happens. :)

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              2
              • D DRoscoe

                @kshegunov Oh dear God.. I got code blind! Copy and paste error.

                Thanks!

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @DRoscoe
                For any productive programmer it will happen sometimes :)
                My all time favorite is

                class Main
                SomeClass* mX;

                then somewhere else
                SomeClass* mX = new SomeClass()

                And go doh a little later. :)

                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