The role and usage of a class associated with multithreading is much like the Android syntax: 1,qdialog dialog base class, you need to select the Qdialog class when you create a new QT GUI project. The ===baseactivity class 2,qpushbutton button control. The ===button class (required when defining parameters in the header file. h, such as: Qpushbutton *stopbtn) 3,setwindowtitle (tr ("thread")); the caption in the Popup dialog window is "thread" (The "-a" notation is used when invoking a method in a control class, for example: Window->addwidget (Qpushbutton)); 4,qhboxlayout the horizontal layout manager, which is used when loading controls dynamically. ===linearlayout Class 5, create a custom threading class, first to inherit the Qthread class, code: Class Workthread:p ublic qthread{q_object}; The semicolon behind the brackets should have. To import a package, #include <qthread>===extends thread 6, constructor notation: in the. h file
Classconsumer:publicqthread
{
Public
Consumer ();
};
. cpp file:
#include "Consumer.h"
Consumer::consumer () {}
7, Button control Click event: The method used in the. h file is public slots: type. ===public onclick (view view) {}
8,connect (Pushbtn,slgnal (onclicked (), This,slots (Slotstart ())), if the slot () function is inside the close () function, click the Pushbtn button and close the dialog box directly.
9,qmutex class (mutex), asynchronous thread, lock, Usage: Mutex.lock (); Qdebug ("Hello"); Qdebug ("World"); Mutex.unlock ();
= = = Synchronized {qdebug ("Hello"); Qdebug ("World"); }
The 10,qsemaphore Class (semaphore), the mutex can only be locked once and the semaphore can be obtained multiple times, it may be used to protect a certain number of the same resources. The acquire () function is used to get n resources, and when there are not enough resources, the caller will be blocked until there are sufficient resources available. The release (n) function is used to dispose of n resources. (Take the method in the class with "." Symbol).
11,qwaitcondition (Wake-up Class) Wakeall ().
12, when using the network programming, qtnetwork need to add in the. Pro file. The notation is qt + = Network
13,qudpsocket (UDP socket interface receive broadcast) ->bind (45454,qudpsocket::shareaddress); port number, Qudpsocket:: The role of Shareaddress is to declare that other services can also bind this port number.
Then, if you receive the broadcast, perform the operation within the SLOT function: Connect (receiver,signal (Readyread ()), This,slot (Processpendingdatagram ()));
Qbytearray datagram;
Datagram.resize (Receiver->pendingdatagramsize ());
Receiver->readdatagram (Datagram.data (), datagram.size ());
Ui->label->settext (datagram); Get the contents of the broadcast.
14,qudpsocket (UDP set interface sends broadcast)
Qbytearray datagram= "Morning is very stupid";
Sender->writedatagram (Datagram.data (), Datagram.size (), qhostaddress::broadcast,45454);------------Send the content, Send length, IP, port number ===broadcast