有个简单的方法如下(使用gnu的barcode命令行):
While KBarcode will work, it might be easier to simply use barcode and
ghostscript, each in a QProcess. For example:
QProcess *process1,*process2;
process1->addArgument("/usr/bin/barcode");
process1->addArgument("-b");
accountID = QString::number("123456");
process1->addArgument(accountID);
process1->addArgument("-o");
process1->addArgument("/tmp/barcode");
bstatus = process1->start();
qDebug("status of start process = %d",bstatus);
// delete process1;
QFile file(barcodeImageFile);
if (file.exists()) // remove old barcode if it exists
QFile::remove(barcodeImageFile);
// not sure if these are optimal ghostview parameters but they work
QProcess *proc2 = new QProcess(this);
proc2->addArgument("/usr/bin/gs");
proc2->addArgument("-sOutputFile="+ barcodeImageFile);
proc2->addArgument("-g100x50"); //widthxheight I think
proc2->addArgument("-sDEVICE=pnggray");
proc2->addArgument("-q");
proc2->addArgument("/tmp/barcode");
proc2->addArgument("-c");
proc2->addArgument("showpage");
proc2->addArgument("-c");
proc2->addArgument("quit");
proc2->start();
// ... load barcode into label
QLabel *barCode = new QLabel(this,"barcode");
QPixmap pm("/tmp/barcode.jpg");
barCode->setPixmap(pm);
This is essentially what kbarcode does. It might be portable to Windows as I think someone has ported barcode to windows and ghostview is avaiilable on windows as well.
If you get a more elegant solution then this hack, please post it to this group.