4 Nisan 2017 Salı
3 Nisan 2017 Pazartesi
QT- QVİDEO PLAYER
videoplayer.pro
#-------------------------------------------------
#
# Project created by QtCreator 2017-04-03T15:39:03
#
#-------------------------------------------------
QT += core gui multimedia multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = videoplayer
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
FORMS += dialog.ui
--------------------------------------------------------------------
dialog.h
#ifndef DIALOG_H#define DIALOG_H#include < QDialog>namespace Ui {class Dialog;}class Dialog : public QDialog{Q_OBJECTpublic:explicit Dialog(QWidget *parent = 0);~Dialog();private:Ui::Dialog *ui;};#endif // DIALOG_H------------------------------------------------------------------------------dialog.cpp#include "dialog.h"#include "ui_dialog.h"Dialog::Dialog(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog){ui- > ;setupUi(this);}Dialog::~Dialog(){delete ui;}----------------------------------------------------------------------------main.cpp#include "dialog.h"#include < QApplication>#include< QMediaPlayer>#include< QVideoWidget>#include< QDebug>int main(int argc, char *argv[]){QApplication a(argc, argv);// Dialog w;// w.show();QMediaPlayer* player = new QMediaPlayer;QVideoWidget* vw = new QVideoWidget;player->setVideoOutput(vw);player->setMedia(QUrl::fromLocalFile("//C://Users//dtsis//Desktop//vi.mpg"));vw->setGeometry(100,100,300,400);vw->show();player->play();qDebug() << player->state();return a.exec();}
QT- QMEDİAPLAYER
MyPlayer.pro
#-------------------------------------------------
#
# Project created by QtCreator 2017-04-03T14:07:12
#
#-------------------------------------------------
QT += core gui multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyPlayer
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
FORMS += dialog.ui
----------------------------------------------------------------------
dialog.h
#ifndef DIALOG_H#define DIALOG_H#include < QDialog>#include< QMediaPlayer>#include< QDebug>namespace Ui {class Dialog;}class Dialog : public QDialog{Q_OBJECTpublic:explicit Dialog(QWidget *parent = 0);~Dialog();private slots:void on_sliderProgress_sliderMoved(int position);void on_sliderVolume_sliderMoved(int position);void on_pushButton_clicked();void on_pushButton_2_clicked();void on_durationChanged(quint64 position);void on_positionChanged(quint64 position);private:Ui::Dialog *ui;QMediaPlayer* player;};#endif // DIALOG_H-------------------------------------------------------------dialog.cpp#include " dialog.h"#include " ui_dialog.h"Dialog::Dialog(QWidget *parent) :QDialog(parent),ui(new Ui::Dialog){ui->setupUi(this);player = new QMediaPlayer(this);connect(player,&QMediaPlayer::positionChanged,this,&Dialog::on_positionChanged);connect(player,&QMediaPlayer::durationChanged,this,&Dialog::on_durationChanged);}Dialog::~Dialog(){delete ui;}void Dialog::on_sliderProgress_sliderMoved(int position){player->setPosition(position);}void Dialog::on_sliderVolume_sliderMoved(int position){player->setVolume(position);}void Dialog::on_pushButton_clicked(){// Load Fileplayer->setMedia(QUrl::fromLocalFile("//C://Users/dtsis//Desktop//se.mp3"));player->play();qDebug() < < player->errorString();}void Dialog::on_pushButton_2_clicked(){player->stop();}void Dialog::on_durationChanged(quint64 position){ui->sliderProgress->setMaximum(position);}void Dialog::on_positionChanged(quint64 position){ui->sliderProgress->setValue(position);}----------------------------------------------------------main.cpp#include "dialog.h"#include < QApplication>int main(int argc, char *argv[]){QApplication a(argc, argv);Dialog w;w.show();return a.exec();}----------------------------------------------------------------
QUDP SOCKET
myudp.h
#ifndef MYUDP_H
#define MYUDP_H
#include < QObject>
#include< QUdpSocket>
class MyUDP : public QObject
{
Q_OBJECT
public:
explicit MyUDP(QObject *paretnt = 0);
void SayHello();
signals:
public slots:
void readyRead();
private:
QUdpSocket *socket;
};
#endif // MYUDP_H
-------------------------------------------------------
main.cpp
#include#include "myudp.h"int main(int argc, char *argv[]){QCoreApplication a(argc, argv);MyUDP server;MyUDP client;client.SayHello();client.SayHello();return a.exec();}---------------------------------------------------------myudp.cpp#include " myudp.h"MyUDP::MyUDP(QObject *parent):QObject(parent){socket = new QUdpSocket(this);socket->bind(QHostAddress::Any,1234);connect(socket,SIGNAL(readyRead()),this,SLOT(readyRead()));}void MyUDP::SayHello(){QByteArray Data;Data.append("Hello from UDP ");socket->writeDatagram(Data,QHostAddress::LocalHost,1234);}void MyUDP::readyRead(){QByteArray Buffer;Buffer.resize(socket->pendingDatagramSize());QHostAddress sender;quint16 senderPort;socket->readDatagram(Buffer.data(),Buffer.size(),&sender,&senderPort);qDebug() < < "Message From : " << sender.toString();qDebug() < < "Message Port : " << senderPort;qDebug() < < "Message : " << Buffer << "\n\n\n";}
31 Mart 2017 Cuma
QT NOTES
Prepend ve Append Farkı :
Prepend: Başa Ekle
Append : Sona Ekle
qDEbug ve NOSPACE özelliği
int a = 10 , b=20 ;
qDebug() << a << b;
çıktı : 10 20
eğer arada boşluk istemezsek nospace kullanırız
qDebug().nospace << a << b;
çıktı : 1020
QVEKTOR SINIFI :
Prepend: Başa Ekle
Append : Sona Ekle
qDEbug ve NOSPACE özelliği
int a = 10 , b=20 ;
qDebug() << a << b;
çıktı : 10 20
eğer arada boşluk istemezsek nospace kullanırız
qDebug().nospace << a << b;
çıktı : 1020
QVEKTOR SINIFI :
int main()
{
QVector<int> vect;
vect << 10 << 20 << 30 << 40 << 50;
qDebug() << vect;
// QVector(10, 20, 30, 40, 50)
return 0;
}
Sınıfın clear üye
fonksiyonu vektör içerisindeki tüm elemanları siler. empty fonksiyonu vektörün
içinin boş olup olmadığını bize verir. erase ile elemanlar silinebilir. first
fonksiyonu ve front fonksiyonu ilk elemanı, last fonksiyonu da son elemanı
vermektedir. indexOf ve lastIndexOf fonksiyonlarıyla vektör içerisinde arama
yapılabilir. removeAt belli bir indeksteki elemanı silmek için kullanılır.
QBYTEARRAY :
QByteArray qba(100, 0); // nesnenin içerisinde 100 byte
var, hepsi 0
- clear üye fonksiyonu yine nesne içerisindeki tüm byte’ları silmek
için kullanılır.
- insert fonksiyonlarıyla belli bir pozisyone insert yapılabilir.
- indexOf fonksiyonları arama amacıyla kullanılır.
- Nesnenin içerisindeki belli bir kısım mid fonksiyonuyla çekilip
alınabilir.
- Nesnenin başına ekleme yapmak için prepend fonksiyonları kullanılır.
- Kapasite artımı için reserve, size artırımı için resize fonksiyonları
kullanılmaktadır.
-
Sınıfın setNum fonksiyonları nesnenin içerisine çeşitli türendne değerleri byte
nyte kodlar. Fakat bu fonksiyonlar sona ekleme yapmazlar.
QByteArray qba;
int a = 1234;
qba.setNum(a); // byte'larına ayrıştırıp 4 byte olarak ekler.
QByteArray
QIODevice::readAll();
Bu fonksiyonlar dosya göstericisinin gösterdiği yerden itibaren
parametreleriyle belirtilen miktarda byte değerini okur. İki parmetreli read
fonksiyonu okunan bilgileri bizim verdiğimiz char türden bir adresten itibaren
yerleştirir. Tek parametreli read fonksiyonu ise okunan bilgileri QByteArray
olarak vermektedir. readAll fonksiyonu dosya göstericisinin gösterdiği yerden
dosya sonuna kadar tüm byte’ları okumaktadır.
qint64
QIODevice::write(const char *data);
Birinci fonksiyon belli bir adresten itibaren belli sayıda byte’ı dosya
göstericisinin gösterdiği yerden itibaren dosyay yazar. İkinci fonksiyon bir
yazıyı null karakter görene kadar byte byte dosyaya yazmaktadır. Üçüncü
fonksiyon QByteArray içerisindekileri dosyay yazar.
QFİLEDİALOG:
QFileDialog fileDialog(this, "Bir dosya seçiniz");
Diayalog
penceresi belli bir dizinle de açılabilir:
QFileDialog fileDialog(this, "Bir dosya seçiniz", "c:\\windows");
QFileDialog sınıfının setFilterNames fonksiyonu bizden
filtreleme bilgilerini bir QStringList nesnesi olarak alır. Her filtreleme yazısı
bir yazı ve parantez içerisinde joker karakterlerinden oluşmaktadır. Örneğin:
QFileDialog fileDialog(this, "Bir dosya seçiniz", "c:\\windows");
QStringList filters;
filters << "All File (*.*)" << "Text Files (*.txt)";
fileDialog.setNameFilters(filters);
if (fileDialog.exec() == QFileDialog::Accepted) {
qDebug() << fileDialog.selectedFiles()[0];
}
Biz
setFileMode fonksiyonuyla diyalog
penceresinde yalnızca dizinlerin gösterilmesini sağlayabiliriz. Örneğin:
QFileDialog fileDialog(this, "Bir dosya seçiniz", "c:\\windows");
fileDialog.setFileMode(QFileDialog::DirectoryOnly);
S
ı
n
ı
f
ı
n indexOf üye fonksiyonlar
ı
yaz
ı
içerisinde bir yaz
ı
ya da karakter ararlar. E
ğ
er bulurlarsa bulduklar
ı
yerin yaz
ı
iç
erisindeki indeks numaras
ı
yla bulamazlarsa -1 de
ğ
eri ile geri dönerler.
S
ı
n
ı
f
ı
n indexOf üye fonksiyonlar
ı
yaz
ı
içerisinde bir yaz
ı
ya da karakter ararlar. E
ğ
er bulurlarsa bulduklar
ı
yerin yaz
ı
iç
erisindeki indeks numaras
ı
yla bulamazlarsa -1 de
ğ
eri ile geri dönerler.







