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. Issues about the function of remove() and clear() from QMap
Forum Updated to NodeBB v4.3 + New Features

Issues about the function of remove() and clear() from QMap

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 558 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.
  • Yandong LuoY Offline
    Yandong LuoY Offline
    Yandong Luo
    wrote on last edited by
    #1

    Hi, I try to use buttons to delete all of the items in QMap. So I use the function of clear() from QMap. But when I click the button, the program exits abnormally. What happened to this?

    void MainWindow::Btn_Read_Click(){
        if(Component_List[Button_Index-1].Button_Read->text() == tr("Stop")){
         port->PauseRead();
          }
    }
    

    .h file

    QMap<int, QByteArray> m_writeData;
    
    void Serial_Service::PauseRead()
    {
        qDebug()<<"pause";
        /* qDeleteAll(m_writeData.begin(),m_writeData.end());*/
    
        m_writeData.clear();
        m_timer->stop();
    }
    

    20210316232241.png

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      As always - use a debugger and see where it crashes.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • nageshN Offline
        nageshN Offline
        nagesh
        wrote on last edited by
        #3

        @Yandong-Luo debug output shows some print "data : ..... length : 9" it means crashing is not happening due to map.clear()/PauseRead().
        Use debugger to locate the crash

        Yandong LuoY 1 Reply Last reply
        0
        • nageshN nagesh

          @Yandong-Luo debug output shows some print "data : ..... length : 9" it means crashing is not happening due to map.clear()/PauseRead().
          Use debugger to locate the crash

          Yandong LuoY Offline
          Yandong LuoY Offline
          Yandong Luo
          wrote on last edited by
          #4

          @nagesh @Christian-Ehrlicher Thanks for your help! I use debugger to locate the crash and I found the program will run to this function and then crash. I still don't know what happens. if I don't use clear(), the program will not crash.

          Snipaste_2021-03-17_08-59-02.png

          1 Reply Last reply
          0
          • nageshN Offline
            nageshN Offline
            nagesh
            wrote on last edited by
            #5

            Does m_Writedata map object being used in any thread during clear operation?

            Yandong LuoY 1 Reply Last reply
            2
            • nageshN nagesh

              Does m_Writedata map object being used in any thread during clear operation?

              Yandong LuoY Offline
              Yandong LuoY Offline
              Yandong Luo
              wrote on last edited by
              #6

              @nagesh Really Thanks for your help. I solved it!

              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