(系统提示对话框)
switch(QMessageBox::warning(this, "Warning",
"Database file is opened,\n"
"please close it first.\n"
"Close database file?",
"Yes", "No", 0, 1)) {
case 0:
ui->label_temp->setText("yes");
db.close(); // close database
dbOpened = false;
openFile(); // open file dialog
showTable(curtTable);
break; // pay attention to here
case 1:
ui->label_temp->setText("no");
break; // and here
16/07/2009
Timer event
(定时发生器函数)
#include “qtimer.h”
in main.cpp main function add:
startTimer(100) //start timer, and timer event triggered every 100 ms
PS: it is a little bit strange here. i don't need to declare a QTimer class. i may find the reason in the future since i am a just beginner in Qt
in main.h add:
void timerEvent(QTimerEvent *event);
in main.cpp add:
void MainWindow::timerEvent(QTimerEvent *event
-----------------------
Edit:
my concern was right, my previous code was wrong. i actually calling the system timer event, not the timer which i created.
here is the correct code:
#include
in main.h add:
QTimer *timer1;
void timerEvent();
in main.cpp add:
timer1 = new QTimer(this); // start timer event
connect(timer1, SIGNAL(timeout()), this, SLOT(timerEvent()));
timer1->start(250);
MainWindow::timerEvent()
{
........
}
#include “qtimer.h”
in main.cpp main function add:
startTimer(100) //start timer, and timer event triggered every 100 ms
PS: it is a little bit strange here. i don't need to declare a QTimer class. i may find the reason in the future since i am a just beginner in Qt
in main.h add:
void timerEvent(QTimerEvent *event);
in main.cpp add:
void MainWindow::timerEvent(QTimerEvent *event
-----------------------
Edit:
my concern was right, my previous code was wrong. i actually calling the system timer event, not the timer which i created.
here is the correct code:
#include
in main.h add:
QTimer *timer1;
void timerEvent();
in main.cpp add:
timer1 = new QTimer(this); // start timer event
connect(timer1, SIGNAL(timeout()), this, SLOT(timerEvent()));
timer1->start(250);
MainWindow::timerEvent()
{
........
}
Find application icon
(寻找系统图标)
in KDE:
$ kde-config --path icon
will list all icon directory.
in GNONE:
$ gnome-config –datadir
will list a path which contains a folder called “pixmaps”.
in KDE:
$ kde-config --path icon
will list all icon directory.
in GNONE:
$ gnome-config –datadir
will list a path which contains a folder called “pixmaps”.
Get total record count (SQLite)
my_sqlModel = new QSqlQueryModel(); //define a new sql model
my_sqlModel.setQuery(“select * from item”);
int cols = my_sqlModel.rowCount();
Qt Installation in Linux
(Qt 在Linux上的安装)
1.download Qt SDK
2.go to the downloaded file folder:
On Linux/Unix, need to make the file executable in order to run it. You can either do this with your desktop's file manager or, at the command line, type:
$ chmod u+x qt-sdk-linux-x86-opensource-2009.02.bin
should now be able to execute the file as normal. to do this from the command line by typing:
$ ./qt-sdk-linux-x86-opensource-2009.02.bin
3.install GNU C++ compliler:
$ sudo apt-get install g++
$ sudo apt-get install build-essential
1.download Qt SDK
2.go to the downloaded file folder:
On Linux/Unix, need to make the file executable in order to run it. You can either do this with your desktop's file manager or, at the command line, type:
$ chmod u+x qt-sdk-linux-x86-opensource-2009.02.bin
should now be able to execute the file as normal. to do this from the command line by typing:
$ ./qt-sdk-linux-x86-opensource-2009.02.bin
3.install GNU C++ compliler:
$ sudo apt-get install g++
$ sudo apt-get install build-essential
Create second window/form/dialog
(新建窗口)
Add New.. Qt – Qt Designer Form Class
Need to include newform.h in mainwindow.cpp file where has slot to open this new window;
Add "extern newDialog *newdialog" in mainwindow.cpp;
Add "newDialog *newdialog" in newwindow.cpp;
Then, in click-button which open new window slot, add:
Add New.. Qt – Qt Designer Form Class
Need to include newform.h in mainwindow.cpp file where has slot to open this new window;
Add "extern newDialog *newdialog" in mainwindow.cpp;
Add "newDialog *newdialog" in newwindow.cpp;
Then, in click-button which open new window slot, add:
void MainWindow::on_pushButton_clicked()
{
if (!newdialog)
newdialog = new newDialog (NULL);
newdialog->exec();
}
The above method creates dialog in heap, so when i click close(), i don't delete it from memory. To close dialog or window completely, the code needs to be changed as:
void MainWindow::on_pushButton_clicked()
{
newDialog newdialog(NULL);
newdialog.exec();
}
{
newDialog newdialog(NULL);
newdialog.exec();
}
we can not use:
cyclescrdialog.show();
show() does not block, so you'll only see a quick flash of your dialog, as it'll be destroyed immediately after calling show() ( when exiting the method ). Using exec() blocks until dialog is closed by the user.
if create new a window/dialog by using code, and did not pre-create window/dialog from “add new.. QT Designer form class”, the new window/dialog may be no shows on the top. This is because that the new window/dialog does not have a parent window/dialog. In order to make sure the new window/dialog shows on the top, use “add new.. QT Designer form class” create a new window/dialog first.
Globle variabal definition
(全局变量定义)
Assume I have a.cpp b.cpp c.cpp and I need use integer i in all three of them.
I declare extern int i in globvar.h file;
Define int i in globevar.cpp file;
#include globvar.h file in all three .cpp files.
Varible definition
(变量定义)
parameter definition should be in .h file. If this variable is used in this window/form (qqWidget.h), just declare in “private:”. But if used in anther window/form, should declare in “public:”.
// globalvar.h
#ifndef MYGLOBALS
#define MYGLOBALS
extern int variable1;
extern int variable2;
#endif
...
// globalvar.cpp implementation
int variable1= 0;
int variable = 0;
Qt is not qute
my qt program's gui looks like normal...
need to add style header in the including file:
#include
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
a.setStyle(new QPlastiqueStyle); //this command must be in front of ”return a.exec()”
return a.exec();
}
Qt4.5 Installation in Windows
(Qt4.5 安装)
to install Qt, need to download and install all three files from Qt website:
-qt-creator-win-opensource-1.1.0.exe
-qt-win-opensource-4.5.1-mingw.exe
-qt-sdk-win-opensource-2009.02.exe
after drag and drop component, no need to declare it again in project.
but need to add ui-> in front of each used component if you wanna to use/edit it.
-qt-win-opensource-4.5.1-mingw.exe
-qt-sdk-win-opensource-2009.02.exe
after drag and drop component, no need to declare it again in project.
but need to add ui-> in front of each used component if you wanna to use/edit it.
09/07/2009
2D barcodes creator/decoder -- Libdmtx
(2维条码生成/解码软件)
Libdmtx is a 2D barcode, or Data Matrix barcodes, creator and decoder.
Libdmtx is a 2D barcode, or Data Matrix barcodes, creator and decoder.
it took me a while to install it. here is mainly procedure of installation:
download libdmtx-0.7.0.tar.gz from http://www.libdmtx.org/
go to new libdmtx folder
i got an error message:
download ImageMagick source file, unpacked,
(edit: I may need this:
i may need to install g++ before install ImageMagick
got anther error when i ran ./configure:
ok, need to install libperl
then, go back to install ImageMagick, and libdmtx.
all done..
To read a 2D barcode:
PS: This command will take a while (maybe 5 to 15 seconds) to finish decoding a 2D barcode image.
To speed up decoding, take a look command option.
Edit:
get web-cam capture software from here:
Fedora install:
may need to install GDlib:
http://www.libgd.org/Downloads
take a photo with webcam:
$ tar -zxf libdmtx-0.7.0.tar.gz
go to new libdmtx folder
$ ./configure
i got an error message:
checking for MAGICK... no
configure: error: dmtxread/dmtxwrite requires Wand >= 6.2.4
that's because i am using ubuntu. alright, i need to install ImageMagick from the source. download ImageMagick source file, unpacked,
$ ./configure
$ make
$ sudo make install
(edit: I may need this:
$ sudo apt-get install libmagick++-dev
$ sudo apt-get install libgraphicsmagick1-dev
) i may need to install g++ before install ImageMagick
$ sudo apt-get install g++
got anther error when i ran ./configure:
/usr/bin/ld: cannot find -lperl
ok, need to install libperl
$ sudo apt-get install libperl-dev
then, go back to install ImageMagick, and libdmtx.
all done..
To read a 2D barcode:
$ dmtxread /~/Desktop/image.png
$ dmtxread -N 1 /home/czhang/mypro/UIM.jpg >> /home/czhang/mypro/UIM.txt
read barcode and export code to text file.PS: This command will take a while (maybe 5 to 15 seconds) to finish decoding a 2D barcode image.
To speed up decoding, take a look command option.
To create a 2D barcode:
$ dmtxwrite <(echo -n 2dbarcodecontent) -o image.png
Edit:
get web-cam capture software from here:
http://www.firestorm.cx/fswebcam/
Fedora install:
root$ yum install fswebcam
may need to install GDlib:
http://www.libgd.org/Downloads
take a photo with webcam:
$ fswebcam -F 15 -r 352x288 --no-banner --save /mnt/cdrive/UIM.jpg
Subscribe to:
Posts (Atom)