Summary of QT Development

Source: Internet
Author: User
Tags usleep high cpu usage

Http://blog.csdn.net/kerry_xiaowei/article/details/6367570

Http://mobile.51cto.com/symbian-270600.htm

The audio and video solutions in QT are as follows:

Phonon framework

 

QT is really a little rubbish, and a delay is also so troublesome

 

  1. Qtime;
  2. T. Start ();
  3. While (T. elapsed () <1000)
  4.   Qcoreapplication: processevents ();
  5. The program keeps responding to events.

Qwaitcondition
Waitcond; waitcond. Wait (400); // or any other
Time in [MS]

Step 2: solve the problem of high CPU usage-make the program sleep properly.

 
 
  1. Qtime T;
  2. T. Start ();
  3. While (T. elapsed () <250)
  4. {
  5. Qcoreapplication: processevents ();
  6. Usleep (10000); // both sleep and usleep have been obsolete. We recommend that you use nanosleep instead.
  7. }

 

Char * BMP = new char [Len + 1]; memcpy (BMP, (char *) Ba. Data (), Len );
BMP [Len + 1] = '\ 0 ';
Wchar wsz [1024] = {0 };
Swprintf (wsz, Len + 1, l "% s", BMP );
Lpcwstr P = wsz;

 

 

 

Start a new program in QT:

Qprocess: startdetached (qstring: fromwchararray (m_strsetupfile.c_str ()));

 

In QT, the interface is processed as follows:

Qapp-> processevent ();

 

Memory Management in QT and Memory leakage handling:
In QT, if a parent is specified in an object definition, the structure of the object is completed by its parent analysis.
For example

Qtoolbar parent;
Qlabel * label = new qlabel ("this is a label", & parent );
Here, the Delete label is completed in the parent destructor.

If multiple objects are released, consider the sequence:

QIcon *ss =  new  QIcon(tempimage); //2      QPixmap* tempimage1 =  new  QPixmap( ss->pixmap(tempimage.size(),QIcon::Disabled) ); //3 // Memory cannot be released tempimage1.detach();
    deletetempimage1  ;     deleteSS ; Some classes provide other functions called before the delete operation, such as the following detach: tempimage1.detach ();
Delete tempimage1;

Http://blog.csdn.net/zhangshan415/article/details/7986027 check memory leakage

If qpixmap is used for performance problems, you can consider qpixmapcache and use it to solve the problem of excessive memory usage during image display. See the following article:

Http://blog.csdn.net/a324539017/article/details/6567186

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.