Function: The format of the queue data storage is diversified by using the template on Qtcreator.
Templates are implemented in two ways:
1, the implementation of the template directly in the header file declaration and definition, and other classes through # include "*.h" for inclusion, you can implement calling the class and instantiation.
2, you can directly define the template in the CPP file specific functions, other classes need to call the class, only through the # include "*.cpp" file, if in the form of "*.h", there will be an error.
#ifndef Templaterqueue_h#defineTemplaterqueue_h#include<QQueue>#include<QMutex>#include<QMutexLocker>Template<classT>classtemplaterqueue{ Public: Templaterqueue (); BOOLSetqueuedata (ConstT tmp); BOOLGetqueuedata (T *tmp); intgetqueuelength (); BOOLclearqueue ();Private: Qqueue<T> *M_prqueuedata; BOOLLockflag; Qmutex M_mutex;}; Template<classT>Templaterqueue<T>:: Templaterqueue () {M_prqueuedata=NewQqueue<t>; Lockflag=false;} Template<classT>BOOLTemplaterqueue<t>::setqueuedata (ConstT tmp) {Qmutexlocker Locker (&M_mutex); if(Lockflag = =true) return false; Else{Lockflag=true; M_prqueuedata-Enqueue (TMP); Lockflag=false; return true; }}template<classT>BOOLTemplaterqueue<t>::getqueuedata (T *tmp) {Qmutexlocker Locker (&M_mutex); if(Lockflag = =true) return false; Else{Lockflag=true; if(m_prqueuedata->IsEmpty ()) {Lockflag=false; return false; } Else { *tmp = m_prqueuedata->dequeue (); Lockflag=false; return true; }}}template<classT>intTemplaterqueue<t>:: Getqueuelength () {Qmutexlocker locker (&M_mutex); if(Lockflag = =true) return false; Else { returnM_prqueuedata->length (); }}template<classT>BOOLTemplaterqueue<t>:: Clearqueue () {Qmutexlocker locker (&M_mutex); if(Lockflag = =true) return false; Else{m_prqueuedata-Clear (); return true; }}#endif //Templaterqueue_h
Generic queue template for C + +