#include <QPainter>
#include <QPrinter>
.
.
.
//======= save as pdf file ==============//
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("/your/directory/your/file.pdf");
QPainter painter;
if(!painter.begin(&printer)) // fail to open file
{
qWarning("fail to open file.");
return ;
}
painter.drawText(320,80,"your text1");
painter.drawText(100,110,"your text2");
painter.drawText(100,140,"your text3");
//======== drawing next page ==========//
/*if(!printer.newPage())
{
qWarning("fail in flushing page to disk.");
return;
}
painter.drawText(10,10,"Test 2");*/
//==============================//
painter.end();
ที่มา
https://www.youtube.com/watch?v=lA5D8b_QPxo
วิธีใช้บล็อกนี้ : อ่านจากบทความที่สร้างอันแรกก่อน แล้วค่อยๆอ่านอันถัดๆมา จะเข้าใจได้ง่ายกว่า, ผู้เขียนใช้ QT creator 3.0.1 Based on Qt 5.2.1 (GCC 4.6.1, 64 bit) บน Ubuntu 15.04 64 bit Line ID : kong_imi E-mail : niran@flowco.co.th
วันอาทิตย์ที่ 24 กันยายน พ.ศ. 2560
วันอาทิตย์ที่ 24 มกราคม พ.ศ. 2559
sqlite3 Backup database and Restore database
Backing up the database
To make a backup copy of the database, simply do a "dump" and redirect the results to a file.cd /home/sqlite sqlite3 sample.db .dump > sample.bak
Restoring the database
Restoring the database from a backup is just as easy as backing up, except we must make sure the destination database is empty first. Alternatively you may want to delete or rename the destination database and let sqlite create a new one for you.cd /home/sqlite mv sample.db sample.db.old sqlite3 sample.db < sample.bak
ที่มา
http://www.ibiblio.org/elemental/howto/sqlite-backup.html
วันอาทิตย์ที่ 8 พฤศจิกายน พ.ศ. 2558
qt thread
https://youtu.be/JaGqGhRW5Ks
https://www.youtube.com/watch?v=yazMHbIew0Q
https://www.youtube.com/watch?v=yazMHbIew0Q&t=444s
https://www.youtube.com/watch?v=yazMHbIew0Q
https://www.youtube.com/watch?v=yazMHbIew0Q&t=444s
วันจันทร์ที่ 19 ตุลาคม พ.ศ. 2558
ตัวอย่าง qt date time
http://apiexamples.com/cpp/QtCore/QDate.html
http://apiexamples.com/cpp/QtCore/QTime.html
http://apiexamples.com/cpp/QtCore/QTime.html
วันศุกร์ที่ 2 ตุลาคม พ.ศ. 2558
ต่อข้อมูล string (qt append string)
การเชื่อมต่อ string เป็นเรื่องยากสำหรับผมมาก เพราะว่าหาตัวอย่างยังไงก็หาไม่เจอ
จริงๆแล้วมันไม่ได้ยากหรอก แต่เราใช้คำในการค้นหา ไม่ตรงกับความต้องการ(อีกแล้ว)
การเพิ่มข้อมูล string หรือการต่อข้อมูล string (Append string) สามารถทำได้ดังนี้
#include <QDebug>
#include <QString>
.
.
.
QString your_name = "Niran";
QString message = "Your name is " + your_name;
qDebug() << message;
หรือ
QString message = "Your name is ";
message += your_name;
qDebug() << message;
หรือ
QString message = "Your name is ";
message.append(your_name);
qDebug() << message;
ที่มา
http://www.qtcentre.org/threads/33603-how-to-concatenate-a-variable-with-a-string
จริงๆแล้วมันไม่ได้ยากหรอก แต่เราใช้คำในการค้นหา ไม่ตรงกับความต้องการ(อีกแล้ว)
การเพิ่มข้อมูล string หรือการต่อข้อมูล string (Append string) สามารถทำได้ดังนี้
#include <QDebug>
#include <QString>
.
.
.
QString your_name = "Niran";
QString message = "Your name is " + your_name;
qDebug() << message;
หรือ
QString message = "Your name is ";
message += your_name;
qDebug() << message;
หรือ
QString message = "Your name is ";
message.append(your_name);
qDebug() << message;
ที่มา
http://www.qtcentre.org/threads/33603-how-to-concatenate-a-variable-with-a-string
convert int to string
วันนี้เขียนโปรแกรม ที่จำเป็นต้อง convert จาก int เป็น string
ตอนแรกก็งงอยู่พักใหญ่ ทำยังไงหว่า เลยถาม google เหมือนเดิม
แต่ถามครั้งแรกมันแสดงผลไรมาไม่รู้เยอะแยะ ไม่ตรงกับที่เราต้องการ
ก็ต้องเปลี่ยนคำถามใหม่ (สอนให้รู้ว่า ต้องตั้งคำถามให้ตรงคำตอบ) ก็จะได้คำตอบที่ต้องการ 555
วิธีเปลี่ยนจาก int เป็น string คือ
int i=42;
QString s = QString::number(i);
ที่มา
http://stackoverflow.com/questions/3211771/how-to-convert-int-to-qstring
ตอนแรกก็งงอยู่พักใหญ่ ทำยังไงหว่า เลยถาม google เหมือนเดิม
แต่ถามครั้งแรกมันแสดงผลไรมาไม่รู้เยอะแยะ ไม่ตรงกับที่เราต้องการ
ก็ต้องเปลี่ยนคำถามใหม่ (สอนให้รู้ว่า ต้องตั้งคำถามให้ตรงคำตอบ) ก็จะได้คำตอบที่ต้องการ 555
วิธีเปลี่ยนจาก int เป็น string คือ
int i=42;
QString s = QString::number(i);
ที่มา
http://stackoverflow.com/questions/3211771/how-to-convert-int-to-qstring
วันพฤหัสบดีที่ 17 กันยายน พ.ศ. 2558
qt database ตัวอย่าง 2
ก่อนเขียน code ต้องแก้ไข .pro ด้วยนะ
QT += sql
#include <QCoreApplication>
#include <QtSql/QSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/home/kong/test-console-application/test");
if (!db.open()){
qDebug() << db.lastError() << endl;
}
else{
qDebug()<<"open database" << endl;
}
qDebug() << db.tables();
QSqlQuery query;
query.exec("select * from hose");
while(query.next()){
int hose_id = query.value(0).toInt();
qDebug() << "hose_id : " << hose_id << endl;
int pump_id = query.value(1).toInt();
qDebug() << "pump_id : " << pump_id << endl;
int hose_number = query.value(2).toInt();
qDebug() << "hose_number : " << hose_number << endl;
}
return a.exec();
}
QT += sql
#include <QCoreApplication>
#include <QtSql/QSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/home/kong/test-console-application/test");
if (!db.open()){
qDebug() << db.lastError() << endl;
}
else{
qDebug()<<"open database" << endl;
}
qDebug() << db.tables();
QSqlQuery query;
query.exec("select * from hose");
while(query.next()){
int hose_id = query.value(0).toInt();
qDebug() << "hose_id : " << hose_id << endl;
int pump_id = query.value(1).toInt();
qDebug() << "pump_id : " << pump_id << endl;
int hose_number = query.value(2).toInt();
qDebug() << "hose_number : " << hose_number << endl;
}
return a.exec();
}
สมัครสมาชิก:
บทความ (Atom)