Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;Linux:等同于OpenPrinter_C++_Linux_Qt_Printing - Fatal编程技术网

C++ C++;Linux:等同于OpenPrinter

C++ C++;Linux:等同于OpenPrinter,c++,linux,qt,printing,C++,Linux,Qt,Printing,我在用Qt。我需要直接在打印机上写一些文字。在windows上,我可以使用winapi OpenPrinter和WritePrinter执行此操作,但我需要此代码在linux上运行,但在linux上找不到此函数OpenPrinter。我知道我可以像这样直接写入linux/dev/usb/lpX文件: char *dev = "/dev/usb/lp0"; int printerfile = open(dev, O_RDWR | O_NOCTTY | O_NDELAY) ; if (printer

我在用Qt。我需要直接在打印机上写一些文字。在windows上,我可以使用winapi OpenPrinter和WritePrinter执行此操作,但我需要此代码在linux上运行,但在linux上找不到此函数OpenPrinter。我知道我可以像这样直接写入linux/dev/usb/lpX文件:

char *dev = "/dev/usb/lp0";
int printerfile = open(dev, O_RDWR | O_NOCTTY | O_NDELAY) ;
if (printerfile < 0)
{
        cout << "Failed to open "<<dev;
        exit(-1);
}
string str = "test 12345";
write(printerfile,str.c_str(),str.length());
char*dev=“/dev/usb/lp0”;
int printerfile=open(dev,O|RDWR | O|NOCTTY | O|NDELAY);
if(printerfile<0)
{

cout您可以尝试通过以下命令了解有关您的Linux操作系统连接打印机的更多信息:

[udevadm info -q all -n /dev/usb/lp0]
输出如下所示:

-------------
P: /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-
1.2:1.0/usbmisc/lp0
N: usb/lp0
E: DEVNAME=/dev/usb/lp0
E: DEVPATH=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-
1.2:1.0/usbmisc/lp0
E: MAJOR=180
E: MINOR=0
E: SUBSYSTEM=usbmisc
E: UDEV_LOG=3
-------------

你不想直接打开打印机。机器上不一定有打印机。很多打印机都是联网的。为什么不像一个守法的Qt公民一样使用QPrinter,不再担心操作系统特定的东西呢?否则,使用CUPS接口(基本上,运行
lp
)@n.m.我试过了,但这台QPrinter在打印机点阵@SimonKraemer上有问题