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. std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;

std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 3 Posters 3.8k 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.
  • Taz742T Offline
    Taz742T Offline
    Taz742
    wrote on last edited by Taz742
    #1
    void ThreadAutomaticSend::run()
    {
        qDebug() << "before size: " << globalall->AutoSet.size() << "insert size: " << globalall->AutoSetINSERT.size() << "del size: " << globalall->AutoSetDELETE.size();
    
        while(!globalall->AutoSetINSERT.empty()){
            std::pair<QDateTime, AutoSend*> pr = *globalall->AutoSetINSERT.begin();
            globalall->AutoSetINSERT.erase(globalall->AutoSetINSERT.find(pr));
            if (globalall->AutoSet.find(pr) == globalall->AutoSet.end()) {
                globalall->AutoSet.insert(pr);
                qDebug() << "araa";
            }
        }
    
        while(!globalall->AutoSetDELETE.empty()){
            std::pair<QDateTime, AutoSend*> pr = *globalall->AutoSetDELETE.begin();
            globalall->AutoSetDELETE.erase(globalall->AutoSetDELETE.find(pr));
            if (globalall->AutoSet.find(pr) != globalall->AutoSet.end()) {
                globalall->AutoSet.erase(globalall->AutoSet.find(pr));
                qDebug() << "aris";
            }
        }
    
        qDebug() << "after size: " << globalall->AutoSet.size() << "insert size: " << globalall->AutoSetINSERT.size() << "del size: " << globalall->AutoSetDELETE.size();
    
        CHildThreadd *childthrd;
    
        for(globalall->AutoSetITerator = globalall->AutoSet.begin(); globalall->AutoSetITerator != globalall->AutoSet.end(); globalall->AutoSetITerator++){
           std::pair<QDateTime, AutoSend*> pr = *globalall->AutoSetITerator;
           if (QDateTime::currentDateTime() >= pr.first) {
               globalall->AutoSetDELETE.insert(pr);
               childthrd = new CHildThreadd();
               connect(childthrd, SIGNAL(finished()), childthrd, SLOT(deleteLater()));
               childthrd->run(pr.second);
           }
        }
    }
    

    AutoSet is Main SET.

    Taz742T 1 Reply Last reply
    0
    • Taz742T Taz742
      void ThreadAutomaticSend::run()
      {
          qDebug() << "before size: " << globalall->AutoSet.size() << "insert size: " << globalall->AutoSetINSERT.size() << "del size: " << globalall->AutoSetDELETE.size();
      
          while(!globalall->AutoSetINSERT.empty()){
              std::pair<QDateTime, AutoSend*> pr = *globalall->AutoSetINSERT.begin();
              globalall->AutoSetINSERT.erase(globalall->AutoSetINSERT.find(pr));
              if (globalall->AutoSet.find(pr) == globalall->AutoSet.end()) {
                  globalall->AutoSet.insert(pr);
                  qDebug() << "araa";
              }
          }
      
          while(!globalall->AutoSetDELETE.empty()){
              std::pair<QDateTime, AutoSend*> pr = *globalall->AutoSetDELETE.begin();
              globalall->AutoSetDELETE.erase(globalall->AutoSetDELETE.find(pr));
              if (globalall->AutoSet.find(pr) != globalall->AutoSet.end()) {
                  globalall->AutoSet.erase(globalall->AutoSet.find(pr));
                  qDebug() << "aris";
              }
          }
      
          qDebug() << "after size: " << globalall->AutoSet.size() << "insert size: " << globalall->AutoSetINSERT.size() << "del size: " << globalall->AutoSetDELETE.size();
      
          CHildThreadd *childthrd;
      
          for(globalall->AutoSetITerator = globalall->AutoSet.begin(); globalall->AutoSetITerator != globalall->AutoSet.end(); globalall->AutoSetITerator++){
             std::pair<QDateTime, AutoSend*> pr = *globalall->AutoSetITerator;
             if (QDateTime::currentDateTime() >= pr.first) {
                 globalall->AutoSetDELETE.insert(pr);
                 childthrd = new CHildThreadd();
                 connect(childthrd, SIGNAL(finished()), childthrd, SLOT(deleteLater()));
                 childthrd->run(pr.second);
             }
          }
      }
      

      AutoSet is Main SET.

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by
      #2

      This problem has been solved:

      struct AutoSend{
          int TCPUID;
          QDateTime When;
          QString Message;
          QString Mobile;
          int TUID;
          int CUID;
      
          AutoSend(int tcpuid, QDateTime when, QString message, QString mobile, int tuid, int cuid) : 
          TCPUID(tcpuid), When(when), Message(message), Mobile(mobile), TUID(tuid), CUID(cuid){}
      };
      
      struct mycomp{
          inline bool operator()(const AutoSend* left, const AutoSend* right){
              return left->When < right->When;
          }
      };
      
          // AutoThread//
              std::set<AutoSend*, mycomp> AutoSet;
              std::set<AutoSend*, mycomp> AutoSetINSERT;
              std::set<AutoSend*, mycomp> AutoSetDELETE;
              std::set<AutoSend*, mycomp> ::iterator AutoSetITerator;
          // AutoThread End.//
      

      But I still need an answer.
      Why not deleted?

      Taz742T 1 Reply Last reply
      0
      • Taz742T Taz742

        This problem has been solved:

        struct AutoSend{
            int TCPUID;
            QDateTime When;
            QString Message;
            QString Mobile;
            int TUID;
            int CUID;
        
            AutoSend(int tcpuid, QDateTime when, QString message, QString mobile, int tuid, int cuid) : 
            TCPUID(tcpuid), When(when), Message(message), Mobile(mobile), TUID(tuid), CUID(cuid){}
        };
        
        struct mycomp{
            inline bool operator()(const AutoSend* left, const AutoSend* right){
                return left->When < right->When;
            }
        };
        
            // AutoThread//
                std::set<AutoSend*, mycomp> AutoSet;
                std::set<AutoSend*, mycomp> AutoSetINSERT;
                std::set<AutoSend*, mycomp> AutoSetDELETE;
                std::set<AutoSend*, mycomp> ::iterator AutoSetITerator;
            // AutoThread End.//
        

        But I still need an answer.
        Why not deleted?

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by Taz742
        #3

        Now there is another problem:

        I added two new structures in AutoSetINSERT;
        AutoSend * t1 = new (1, QDateTime::currentDateTime, "bbb", "597112233", 2, 3);
        AutoSend * t2 = new (1, QDateTime::currentDateTime, "bbb", "597112233", 4, 3);

        AutoSetINSERT(t1);
        AutoSetINSERT(t2);

        Yes, Now AutoSetINSERT.size() = 2 because i replace std::set to std::multiset

        t1 and t2 are different.
        t1 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 2, 3);
        t2 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 4, 3);

        continue:

            while(!globalall->AutoSetINSERT.empty()){
                AutoSend* pr = *globalall->AutoSetINSERT.begin();
                globalall->AutoSetINSERT.erase(globalall->AutoSetINSERT.find(pr));
                if (globalall->AutoSet.find(pr) == globalall->AutoSet.end()) {
                    globalall->AutoSet.insert(pr);
                    qDebug() << "araa";
                }
            }
        

        first item inserted at the AutoSET, because dont fint it. BUT The second thing tells me that he is already there.

        but they are different from each other:
        t1 and t2 are different.
        t1 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 2, 3);
        t2 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 4, 3);

        How can I solve this problem? So that any difference can be found?

        K 1 Reply Last reply
        0
        • Taz742T Taz742

          Now there is another problem:

          I added two new structures in AutoSetINSERT;
          AutoSend * t1 = new (1, QDateTime::currentDateTime, "bbb", "597112233", 2, 3);
          AutoSend * t2 = new (1, QDateTime::currentDateTime, "bbb", "597112233", 4, 3);

          AutoSetINSERT(t1);
          AutoSetINSERT(t2);

          Yes, Now AutoSetINSERT.size() = 2 because i replace std::set to std::multiset

          t1 and t2 are different.
          t1 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 2, 3);
          t2 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 4, 3);

          continue:

              while(!globalall->AutoSetINSERT.empty()){
                  AutoSend* pr = *globalall->AutoSetINSERT.begin();
                  globalall->AutoSetINSERT.erase(globalall->AutoSetINSERT.find(pr));
                  if (globalall->AutoSet.find(pr) == globalall->AutoSet.end()) {
                      globalall->AutoSet.insert(pr);
                      qDebug() << "araa";
                  }
              }
          

          first item inserted at the AutoSET, because dont fint it. BUT The second thing tells me that he is already there.

          but they are different from each other:
          t1 and t2 are different.
          t1 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 2, 3);
          t2 - > new (1, QDateTime::currentDateTime, "bbb", "597112233", 4, 3);

          How can I solve this problem? So that any difference can be found?

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Taz742

          Wild guess, because your comparison struct mycomp is only on When the QDateTime. When this is used for sorting within your std::set, there is no wonder that with identical date and time the set does not see a difference, because you are not telling the algorithms.

          Vote the answer(s) that helped you to solve your issue(s)

          Taz742T 1 Reply Last reply
          1
          • K koahnig

            @Taz742

            Wild guess, because your comparison struct mycomp is only on When the QDateTime. When this is used for sorting within your std::set, there is no wonder that with identical date and time the set does not see a difference, because you are not telling the algorithms.

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by Taz742
            #5

            @koahnig
            You are talking about?

            struct AutoSend{
                int TCPUID;
                QDateTime When;
                QString Message;
                QString Mobile;
                int TUID;
                int CUID;
            
                AutoSend(int tcpuid, QDateTime when, QString message, QString mobile, int tuid, int cuid) : TCPUID(tcpuid), When(when), Message(message), Mobile(mobile), TUID(tuid), CUID(cuid){}
            
                inline bool operator < (const AutoSend* left){
                    return left->When < When;
                }
            
            
                inline bool operator == (const AutoSend* left){
                    return (left->CUID == CUID && left->Message == Message && left->Mobile == Mobile && left->TCPUID == TCPUID && left->TUID == TUID && left->When == When);
                }
            
                inline bool operator != (const AutoSend* left){
                    return (left->CUID != CUID || left->Message != Message || left->Mobile != Mobile || left->TCPUID != TCPUID || left->TUID != TUID || left->When != When);
                }
            };
            
            Taz742T 1 Reply Last reply
            0
            • Taz742T Taz742

              @koahnig
              You are talking about?

              struct AutoSend{
                  int TCPUID;
                  QDateTime When;
                  QString Message;
                  QString Mobile;
                  int TUID;
                  int CUID;
              
                  AutoSend(int tcpuid, QDateTime when, QString message, QString mobile, int tuid, int cuid) : TCPUID(tcpuid), When(when), Message(message), Mobile(mobile), TUID(tuid), CUID(cuid){}
              
                  inline bool operator < (const AutoSend* left){
                      return left->When < When;
                  }
              
              
                  inline bool operator == (const AutoSend* left){
                      return (left->CUID == CUID && left->Message == Message && left->Mobile == Mobile && left->TCPUID == TCPUID && left->TUID == TUID && left->When == When);
                  }
              
                  inline bool operator != (const AutoSend* left){
                      return (left->CUID != CUID || left->Message != Message || left->Mobile != Mobile || left->TCPUID != TCPUID || left->TUID != TUID || left->When != When);
                  }
              };
              
              Taz742T Offline
              Taz742T Offline
              Taz742
              wrote on last edited by
              #6

              he is working in vector fine

              #include <bits/stdc++.h>
              #include <algorithm>
              #include <vector>
              #include <stack>
              #include <cmath>
              #include <set>
              #include <map>
              
              using namespace std;
              
              const int MAXN = 1e5+1;
              const int  MOD = 1e9+7;
              
              struct abc{
                  int a;
                  int b;
                  int c;
              
              	inline bool operator()(const abc rhs){
              		return rhs.a < a;
              	}	
              
                  inline bool operator == (const abc rhs){
              		return rhs.a == a && rhs.b == b && rhs.c == c;
              	}
              	
              	inline bool operator != (const abc rhs){
              		return rhs.a != a || rhs.c != c || rhs.b != b;
              	}
              };
              
              vector<abc> st;
              
              int main(){
              	
              	abc aa, bb;
              	
              	aa.a = 2;
              	aa.b = 2;
              	aa.c = 3;
              	
              	st.push_back(aa);
              	
              	bb.a = 2;
              	bb.b = 3;
              	bb.c = 3;
              	
              	if(std::find(st.begin(), st.end(), bb) != st.end()){
              		cout << "aa aris";
              	}else{
              		cout << "aa ar aris";	
              	}
              	
              	return 0;
              }
              

              but not set.
              please help me.

              mrjjM K 2 Replies Last reply
              0
              • Taz742T Taz742

                he is working in vector fine

                #include <bits/stdc++.h>
                #include <algorithm>
                #include <vector>
                #include <stack>
                #include <cmath>
                #include <set>
                #include <map>
                
                using namespace std;
                
                const int MAXN = 1e5+1;
                const int  MOD = 1e9+7;
                
                struct abc{
                    int a;
                    int b;
                    int c;
                
                	inline bool operator()(const abc rhs){
                		return rhs.a < a;
                	}	
                
                    inline bool operator == (const abc rhs){
                		return rhs.a == a && rhs.b == b && rhs.c == c;
                	}
                	
                	inline bool operator != (const abc rhs){
                		return rhs.a != a || rhs.c != c || rhs.b != b;
                	}
                };
                
                vector<abc> st;
                
                int main(){
                	
                	abc aa, bb;
                	
                	aa.a = 2;
                	aa.b = 2;
                	aa.c = 3;
                	
                	st.push_back(aa);
                	
                	bb.a = 2;
                	bb.b = 3;
                	bb.c = 3;
                	
                	if(std::find(st.begin(), st.end(), bb) != st.end()){
                		cout << "aa aris";
                	}else{
                		cout << "aa ar aris";	
                	}
                	
                	return 0;
                }
                

                but not set.
                please help me.

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

                @Taz742
                Hi
                Docs says
                "QSet's value data type must be an assignable data type. In addition, the type must provide operator==(), and there must also be a global qHash() function that returns a hash value for an argument of the key's type. "

                So Im wondering how your qHash() looks like ?

                Also place a break point in your == and find out why it thinks they are the same ?

                K 1 Reply Last reply
                0
                • mrjjM mrjj

                  @Taz742
                  Hi
                  Docs says
                  "QSet's value data type must be an assignable data type. In addition, the type must provide operator==(), and there must also be a global qHash() function that returns a hash value for an argument of the key's type. "

                  So Im wondering how your qHash() looks like ?

                  Also place a break point in your == and find out why it thinks they are the same ?

                  K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  @mrjj
                  he is using std::set and AFAIK operator< is enough, isn't t?

                  Vote the answer(s) that helped you to solve your issue(s)

                  mrjjM 1 Reply Last reply
                  0
                  • K koahnig

                    @mrjj
                    he is using std::set and AFAIK operator< is enough, isn't t?

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

                    @koahnig
                    I guess you are right, just wondered with std::pair and a struct pointer

                    1 Reply Last reply
                    0
                    • Taz742T Taz742

                      he is working in vector fine

                      #include <bits/stdc++.h>
                      #include <algorithm>
                      #include <vector>
                      #include <stack>
                      #include <cmath>
                      #include <set>
                      #include <map>
                      
                      using namespace std;
                      
                      const int MAXN = 1e5+1;
                      const int  MOD = 1e9+7;
                      
                      struct abc{
                          int a;
                          int b;
                          int c;
                      
                      	inline bool operator()(const abc rhs){
                      		return rhs.a < a;
                      	}	
                      
                          inline bool operator == (const abc rhs){
                      		return rhs.a == a && rhs.b == b && rhs.c == c;
                      	}
                      	
                      	inline bool operator != (const abc rhs){
                      		return rhs.a != a || rhs.c != c || rhs.b != b;
                      	}
                      };
                      
                      vector<abc> st;
                      
                      int main(){
                      	
                      	abc aa, bb;
                      	
                      	aa.a = 2;
                      	aa.b = 2;
                      	aa.c = 3;
                      	
                      	st.push_back(aa);
                      	
                      	bb.a = 2;
                      	bb.b = 3;
                      	bb.c = 3;
                      	
                      	if(std::find(st.begin(), st.end(), bb) != st.end()){
                      		cout << "aa aris";
                      	}else{
                      		cout << "aa ar aris";	
                      	}
                      	
                      	return 0;
                      }
                      

                      but not set.
                      please help me.

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by koahnig
                      #10

                      @Taz742 said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                      he is working in vector fine

                      #include <bits/stdc++.h>
                      #include <algorithm>
                      #include <vector>
                      #include <stack>
                      #include <cmath>
                      #include <set>
                      #include <map>
                      
                      using namespace std;
                      
                      const int MAXN = 1e5+1;
                      const int  MOD = 1e9+7;
                      
                      struct abc{
                          int a;
                          int b;
                          int c;
                      
                      	inline bool operator()(const abc rhs){
                      		return rhs.a < a;
                      	}	
                      
                          inline bool operator == (const abc rhs){
                      		return rhs.a == a && rhs.b == b && rhs.c == c;
                      	}
                      	
                      	inline bool operator != (const abc rhs){
                      		return rhs.a != a || rhs.c != c || rhs.b != b;
                      	}
                      };
                      
                      vector<abc> st;
                      
                      int main(){
                      	
                      	abc aa, bb;
                      	
                      	aa.a = 2;
                      	aa.b = 2;
                      	aa.c = 3;
                      	
                      	st.push_back(aa);
                      	
                      	bb.a = 2;
                      	bb.b = 3;
                      	bb.c = 3;
                      	
                      	if(std::find(st.begin(), st.end(), bb) != st.end()){
                      		cout << "aa aris";
                      	}else{
                      		cout << "aa ar aris";	
                      	}
                      	
                      	return 0;
                      }
                      

                      but not set.
                      please help me.

                      Your problem is not Qt related.
                      You better check the difference and features in data handling between different containers Your compare function is incomplete and therefore you are getting unexpected results (see your initial post and my initial reply).

                      The same is true for your last post. Now you have added relational operators. Your operator< is handling only part of the data structure. The rest is ignored by your operator and therefore it is ignored within operation of std::set (in case you still using this). You have added more relational operators (operator== and operator!=) but they are not consistent with operator<. This is not healthy programming. In some few cases your code might be sufficient, but as soon as enter the field of containers this is haunting you already.

                      Create a data structure or class without operator< and try to use it in std::set or std::map. The compiler will complain that there is no operator< defined. As soon as you define it, the sets and maps will compile. I am not a 100% sure, but AFAIK most other relational operators are not used. Respectively this might be dependent on your actual stl implementation. Sometimes you see in debug mode error messages when the stl find conflicting relational operators, but that is not always the case.

                      Vote the answer(s) that helped you to solve your issue(s)

                      Taz742T 2 Replies Last reply
                      3
                      • K koahnig

                        @Taz742 said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                        he is working in vector fine

                        #include <bits/stdc++.h>
                        #include <algorithm>
                        #include <vector>
                        #include <stack>
                        #include <cmath>
                        #include <set>
                        #include <map>
                        
                        using namespace std;
                        
                        const int MAXN = 1e5+1;
                        const int  MOD = 1e9+7;
                        
                        struct abc{
                            int a;
                            int b;
                            int c;
                        
                        	inline bool operator()(const abc rhs){
                        		return rhs.a < a;
                        	}	
                        
                            inline bool operator == (const abc rhs){
                        		return rhs.a == a && rhs.b == b && rhs.c == c;
                        	}
                        	
                        	inline bool operator != (const abc rhs){
                        		return rhs.a != a || rhs.c != c || rhs.b != b;
                        	}
                        };
                        
                        vector<abc> st;
                        
                        int main(){
                        	
                        	abc aa, bb;
                        	
                        	aa.a = 2;
                        	aa.b = 2;
                        	aa.c = 3;
                        	
                        	st.push_back(aa);
                        	
                        	bb.a = 2;
                        	bb.b = 3;
                        	bb.c = 3;
                        	
                        	if(std::find(st.begin(), st.end(), bb) != st.end()){
                        		cout << "aa aris";
                        	}else{
                        		cout << "aa ar aris";	
                        	}
                        	
                        	return 0;
                        }
                        

                        but not set.
                        please help me.

                        Your problem is not Qt related.
                        You better check the difference and features in data handling between different containers Your compare function is incomplete and therefore you are getting unexpected results (see your initial post and my initial reply).

                        The same is true for your last post. Now you have added relational operators. Your operator< is handling only part of the data structure. The rest is ignored by your operator and therefore it is ignored within operation of std::set (in case you still using this). You have added more relational operators (operator== and operator!=) but they are not consistent with operator<. This is not healthy programming. In some few cases your code might be sufficient, but as soon as enter the field of containers this is haunting you already.

                        Create a data structure or class without operator< and try to use it in std::set or std::map. The compiler will complain that there is no operator< defined. As soon as you define it, the sets and maps will compile. I am not a 100% sure, but AFAIK most other relational operators are not used. Respectively this might be dependent on your actual stl implementation. Sometimes you see in debug mode error messages when the stl find conflicting relational operators, but that is not always the case.

                        Taz742T Offline
                        Taz742T Offline
                        Taz742
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • K koahnig

                          @Taz742 said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                          he is working in vector fine

                          #include <bits/stdc++.h>
                          #include <algorithm>
                          #include <vector>
                          #include <stack>
                          #include <cmath>
                          #include <set>
                          #include <map>
                          
                          using namespace std;
                          
                          const int MAXN = 1e5+1;
                          const int  MOD = 1e9+7;
                          
                          struct abc{
                              int a;
                              int b;
                              int c;
                          
                          	inline bool operator()(const abc rhs){
                          		return rhs.a < a;
                          	}	
                          
                              inline bool operator == (const abc rhs){
                          		return rhs.a == a && rhs.b == b && rhs.c == c;
                          	}
                          	
                          	inline bool operator != (const abc rhs){
                          		return rhs.a != a || rhs.c != c || rhs.b != b;
                          	}
                          };
                          
                          vector<abc> st;
                          
                          int main(){
                          	
                          	abc aa, bb;
                          	
                          	aa.a = 2;
                          	aa.b = 2;
                          	aa.c = 3;
                          	
                          	st.push_back(aa);
                          	
                          	bb.a = 2;
                          	bb.b = 3;
                          	bb.c = 3;
                          	
                          	if(std::find(st.begin(), st.end(), bb) != st.end()){
                          		cout << "aa aris";
                          	}else{
                          		cout << "aa ar aris";	
                          	}
                          	
                          	return 0;
                          }
                          

                          but not set.
                          please help me.

                          Your problem is not Qt related.
                          You better check the difference and features in data handling between different containers Your compare function is incomplete and therefore you are getting unexpected results (see your initial post and my initial reply).

                          The same is true for your last post. Now you have added relational operators. Your operator< is handling only part of the data structure. The rest is ignored by your operator and therefore it is ignored within operation of std::set (in case you still using this). You have added more relational operators (operator== and operator!=) but they are not consistent with operator<. This is not healthy programming. In some few cases your code might be sufficient, but as soon as enter the field of containers this is haunting you already.

                          Create a data structure or class without operator< and try to use it in std::set or std::map. The compiler will complain that there is no operator< defined. As soon as you define it, the sets and maps will compile. I am not a 100% sure, but AFAIK most other relational operators are not used. Respectively this might be dependent on your actual stl implementation. Sometimes you see in debug mode error messages when the stl find conflicting relational operators, but that is not always the case.

                          Taz742T Offline
                          Taz742T Offline
                          Taz742
                          wrote on last edited by
                          #12

                          @koahnig said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                          Your problem is not Qt related.

                          yes i know.

                          Maybe it's too late. But it works.

                          bool ThreadAutomaticSend::MyCompare(const AutoSend *left, const AutoSend *right)
                          {
                              if (left->Message == right->Message && left->CUID == right->CUID && left->Mobile == right->Mobile && left->TCPUID == right->TCPUID && left->TUID == right->TUID && left->When == right->When) {
                                  return true;
                              }
                          
                              return false;
                          }
                          
                          bool ThreadAutomaticSend::SortCompare(const AutoSend *left, const AutoSend *right)
                          {
                              return left->When < right->When;
                          }
                          
                          void ThreadAutomaticSend::run()
                          {
                              while(!globalall->AutoSetINSERT.empty()){
                                  AutoSend* pr = *globalall->AutoSetINSERT.begin();
                                  globalall->AutoSetINSERT.erase(globalall->AutoSetINSERT.begin());
                                  bool ind = false;
                                  for(globalall->iter = globalall->AutoSet.begin(); globalall->iter != globalall->AutoSet.end(); globalall->iter++){
                                      if (MyCompare(pr, *globalall->iter)) {
                                          ind = true;
                                      }
                                  }
                                  if (!ind) {
                                      globalall->AutoSet.push_back(pr);
                                  }
                              }
                          
                              while(!globalall->AutoSetDELETE.empty()){
                                  AutoSend* pr = *globalall->AutoSetDELETE.begin();
                                  globalall->AutoSetDELETE.erase(globalall->AutoSetDELETE.begin());
                                  for(globalall->iter = globalall->AutoSet.begin(); globalall->iter != globalall->AutoSet.end(); globalall->iter++){
                                      if (MyCompare(pr, *globalall->iter)) {
                                          globalall->AutoSet.erase(globalall->iter);
                                          break;
                                      }
                                  }
                              }
                          
                              std::sort(globalall->AutoSet.begin(), globalall->AutoSet.end(), SortCompare);
                          
                              CHildThreadd *childthrd;
                          
                              for(globalall->iter = globalall->AutoSet.begin(); globalall->iter != globalall->AutoSet.end(); globalall->iter++){
                                 AutoSend* pr = *globalall->iter;
                                 if (QDateTime::currentDateTime() >= pr->When) {
                                     childthrd = new CHildThreadd();
                                     connect(childthrd, SIGNAL(finished()), childthrd, SLOT(deleteLater()));
                                     childthrd->run(pr);
                                 } else {
                                     break;
                                 }
                              }
                          }
                          
                          Taz742T 1 Reply Last reply
                          1
                          • Taz742T Taz742

                            @koahnig said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                            Your problem is not Qt related.

                            yes i know.

                            Maybe it's too late. But it works.

                            bool ThreadAutomaticSend::MyCompare(const AutoSend *left, const AutoSend *right)
                            {
                                if (left->Message == right->Message && left->CUID == right->CUID && left->Mobile == right->Mobile && left->TCPUID == right->TCPUID && left->TUID == right->TUID && left->When == right->When) {
                                    return true;
                                }
                            
                                return false;
                            }
                            
                            bool ThreadAutomaticSend::SortCompare(const AutoSend *left, const AutoSend *right)
                            {
                                return left->When < right->When;
                            }
                            
                            void ThreadAutomaticSend::run()
                            {
                                while(!globalall->AutoSetINSERT.empty()){
                                    AutoSend* pr = *globalall->AutoSetINSERT.begin();
                                    globalall->AutoSetINSERT.erase(globalall->AutoSetINSERT.begin());
                                    bool ind = false;
                                    for(globalall->iter = globalall->AutoSet.begin(); globalall->iter != globalall->AutoSet.end(); globalall->iter++){
                                        if (MyCompare(pr, *globalall->iter)) {
                                            ind = true;
                                        }
                                    }
                                    if (!ind) {
                                        globalall->AutoSet.push_back(pr);
                                    }
                                }
                            
                                while(!globalall->AutoSetDELETE.empty()){
                                    AutoSend* pr = *globalall->AutoSetDELETE.begin();
                                    globalall->AutoSetDELETE.erase(globalall->AutoSetDELETE.begin());
                                    for(globalall->iter = globalall->AutoSet.begin(); globalall->iter != globalall->AutoSet.end(); globalall->iter++){
                                        if (MyCompare(pr, *globalall->iter)) {
                                            globalall->AutoSet.erase(globalall->iter);
                                            break;
                                        }
                                    }
                                }
                            
                                std::sort(globalall->AutoSet.begin(), globalall->AutoSet.end(), SortCompare);
                            
                                CHildThreadd *childthrd;
                            
                                for(globalall->iter = globalall->AutoSet.begin(); globalall->iter != globalall->AutoSet.end(); globalall->iter++){
                                   AutoSend* pr = *globalall->iter;
                                   if (QDateTime::currentDateTime() >= pr->When) {
                                       childthrd = new CHildThreadd();
                                       connect(childthrd, SIGNAL(finished()), childthrd, SLOT(deleteLater()));
                                       childthrd->run(pr);
                                   } else {
                                       break;
                                   }
                                }
                            }
                            
                            Taz742T Offline
                            Taz742T Offline
                            Taz742
                            wrote on last edited by
                            #13

                            @Taz742 said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                            bool ThreadAutomaticSend::SortCompare(const AutoSend *left, const AutoSend *right)
                            {
                            return left->When < right->When;
                            }

                            sorry its not work.

                            
                                std::sort(globalall->AutoSet.begin(), globalall->AutoSet.end(), [](AutoSend *aa, AutoSend *bb){return aa->When < bb->When;});
                            
                            
                            mrjjM 1 Reply Last reply
                            0
                            • Taz742T Taz742

                              @Taz742 said in std::set<std::pair<QDateTime, MyStruct*> > No items are deleted;:

                              bool ThreadAutomaticSend::SortCompare(const AutoSend *left, const AutoSend *right)
                              {
                              return left->When < right->When;
                              }

                              sorry its not work.

                              
                                  std::sort(globalall->AutoSet.begin(), globalall->AutoSet.end(), [](AutoSend *aa, AutoSend *bb){return aa->When < bb->When;});
                              
                              
                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Taz742

                              So the lambda works?

                              Taz742T 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                @Taz742

                                So the lambda works?

                                Taz742T Offline
                                Taz742T Offline
                                Taz742
                                wrote on last edited by
                                #15

                                @mrjj

                                std::sort(globalall->AutoSet.begin(), globalall->AutoSet.end(), [](AutoSend *aa, AutoSend *bb){return aa->When < bb->When;});
                                

                                its yes.

                                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