19 Eylül 2019 Perşembe

QSerialPort Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <QSerialPort>
Constructor
Şöyle yaparız.
QSerialPort port("COM1");
readyRead metodu
Şöyle yaparız.
port.setBaudRate(QSerialPort::Baud4800);
port.setDataBits(QSerialPort::Data8);
port.setStopBits(QSerialPort::OneStop);
port.setParity(QSerialPort::NoParity);
port.setFlowControl(QSerialPort::NoFlowControl);

QObject::connect(&port, &QSerialPort::readyRead,[&port](){
  qDebug() << port.readAll();
});

QObject::connect(&port, &QSerialPort::bytesWritten,[](qint64 bytes){
  qDebug() << bytes;
});

QObject::connect(&port, &QSerialPort::errorOccurred,
                     [](QSerialPort::SerialPortError error){
  qDebug() << error;
});

if (port.open(QSerialPort::ReadWrite)) {
  qDebug() << port.write("Test");
}

12 Eylül 2019 Perşembe

QApplication Sınıfı

Giriş
Şu satırı dahil ederiz.
#include <QApplication>
Qt QApplication ile diğer sınıfları bağlamak için kod üretir. Açıklaması şöyle
Qt preprocess your code and build the real c++ code before compiling, its at this moment QApplication wrap all Q object in the main.cpp file and build the rest of the code from it.
Açıklaması şöyle.
"It handles widget specific initialization, finalization."
constructor
Şöyle yaparız.
#include <QApplication>
#include <QPushButton>

int main(int argc, char **argv)
{
 QApplication app (argc, argv);

 QPushButton button ("Hello world !");
 button.show();

 return app.exec();
}
exec metodu
Örnek
Şöyle yaparız
#include "notepad.h"
#include <QApplication>

int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  Notepad w;
  w.show();

  return a.exec();
}
topLevelWidgets metodu
Şöyle yaparız.
QWidgetList list = QApplication::topLevelWidgets();

QPushButton Sınıfı

Giriş
Şu satırı dahil ederiz
#include <QPushButton>
show metodu
Şöyle yaparız.
QPushButton button ("Hello world !");
button.show();

10 Eylül 2019 Salı

QTcpSocket Sınıfı

Constructor
Şöyle yaparız
QTcpSocket socket;
connectToHost metodu
Şöyle yaparız
socket.connectToHost("198.168.101.230", 4400);
waitForConnected metodu
Örnek
Şöyle yaparız
if(socket.waitForConnected())
{
    qDebug() << "Connected";
    ...
}
else
{
    qDebug() << "Not Connected";
}
Örnek
Şöyle yaparız.
if (!socket->waitForConnected(connectionTimeout))
{
  ...
}
write metodu
Şöyle yaparız
socket.write("HELLO SERVER");