Ready

时间:2019-04-20
本文章向大家介绍Ready,主要包括Ready使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.QT Connect 函数的第五个参数:

1)自动连接(AutoConnection),默认的连接方式,如果信号与槽,也就是发送者与接受者在同一线程,等同于直接连接;如果发送者与接受者处在不同线程,等同于队列连接。
2)直接连接(DirectConnection),当信号发射时,槽函数立即直接调用。无论槽函数所属对象在哪个线程,槽函数总在发送者所在线程执行,即槽函数和信号发送者在同一线程
3)队列连接(QueuedConnection),当控制权回到接受者所在线程的事件循环时,槽函数被调用。槽函数在接受者所在线程执行,即槽函数与信号接受者在同一线程
4)锁定队列连接(QueuedConnection)
Qt::BlockingQueuedConnection:槽函数的调用时机与Qt::QueuedConnection一致,不过发送完信号后发送者所在线程会阻塞,直到槽函数运行完。接收者和发送者绝对不能在一个线程,否则程序会死锁。在多线程间需要同步的场合可能需要这个。
5)单一连接(QueuedConnection)

2.快速排序

int partition(int a[],int low,int high)

{

       int iFlag = a[low];

   while(low<high)

{

      while((low<high)&&(a[high]>=iFlag))

                   high—;

      if(low<high)

  {

       int tmp = a[low];

      a[low] = a[high];

     a[high] = tmp;

  }

  while((low<high)&&(a[low]<=iFlag))

     low++;

if(low<high)

{

       int tmp = a[low];

      a[low] = a[high];

     a[high] = tmp;

}

}

return low;

}

 

void quickSort(int a[],int low,int high)

{

if(low<high)

{

         int iMid = partition(a,low,high);

         quickSort(a,low,iMid-1);

         quickSort(a,iMid+1,high);

}

}

3.链表逆序

struct Node

{

     int iData;

     Node* pNext;

}

Node* reverseList(Node* pHead)

{

   if((NULL==pHead)||(NULL==pHead->pNext))

           return pHead;

   Node* pNewHead = reverse(pHead->pNext);

   pHead->pNext->pNext = pHead;

   pHead->pNext = NULL;

   return pNewHead;

}

4.链表是否有环

bool IsLoop(Node* pHead)

{

       Node* pSlow = pHead;

       Node* pFast = pHead;

       while(pFast&& pFast->pNext)

      {

           pSlow = pSlow->pNext;

           pFast = pFast->pNext->pNext;

           if(pSlow==pFast)

               return true;

     }

     return false;

}

5.内存拷贝

void* mymemcpy(void* dest, void* source, size_t count)

   {

       void* ret = dest;

      if (dest <= source || dest >= (source + count))

       {

         while (count --)

               *dest++ = *source++;

     }

     else

     {

       dest += count - 1;

       source += count - 1;

       while (count--)

                *dest-- = *source--;

     }

      return ret;

   }