class CameraAdapter : public QWidget
{
Q_OBJECT
public:
explicit CameraAdapter(QWidget *parent = 0);
~CameraAdapter();
void closeCamera()const;
void openCamera(const QString& description=QString());
void enumCamera();
private slots:
void onImageCaptured(int id,QImage img);
void onImageSaved(int id, const QString &fileName);
private:
Ui::CameraAdapter *ui;
QCamera* mCamera; //摄像头对象
QCameraViewfinder* mViewfinder; //摄像头取景器
QCameraImageCapture* mImageCapture; //截图对象
};
class HidDev : public QObject
{
Q_OBJECT
public:
explicit HidDev(QObject *parent = 0);
~HidDev();
void enumHidDev();
bool openHidDev(unsigned short vid, unsigned short pid);
void closeHidDev();
int hidWrite(const unsigned char *data, size_t length);
int hidRead();
private:
hid_device* mHidDev = nullptr;
bool mRun = true;
};
class MqttAdapter:public QObject
{
Q_OBJECT
public:
MqttAdapter(QObject* parent=0);
~MqttAdapter();
bool initMqtt(const QString& clientId);
void subScribe(const QString& toptic);
int publicMessage(const QString& message,const QString& topic);
void recvMessage(const char *data,char* topic);
void connectLost(char* cause);
private:
void printConnectError(const int errCode)const;
private:
MQTTClient mClient;
bool mhasConn = false;
};
class PinyinAdapter : public QObject
{
Q_OBJECT
public:
explicit PinyinAdapter(QObject *parent = 0);
void pinyinParse(QString &content,QString& pingying,QString& abbrev);
};
QPixmap getQrCode(const QString& content)
{
QRcode *qrcode;
qrcode=QRcode_encodeString(content.toStdString().c_str(),2,QR_ECLEVEL_Q,QR_MODE_8,1);
qint32 temp_width=200; //宽度
qint32 temp_height=200; //高度
qint32 qrcode_width=qrcode->width>0?qrcode->width:1;
double scale_x=(double)temp_width/(double)qrcode_width;
double scale_y=(double)temp_height/(double)qrcode_width;
QImage mainimg=QImage(temp_width,temp_height,QImage::Format_ARGB32);
QPainter painter(&mainimg);
QColor background(Qt::white);
painter.setBrush(background);
painter.setPen(Qt::NoPen);
painter.drawRect(0,0,temp_width,temp_height);
QColor foreground(Qt::black);
painter.setBrush(foreground);
for(qint32 y=0;ydata[y*qrcode_width+x];
if(b &0x01)
{
QRectF r(x*scale_x,y*scale_y,scale_x,scale_y);
painter.drawRects(&r,1);
}
}
}
return QPixmap::fromImage(mainimg);
}
namespace XZPSQL {
static QSqlDatabase _db;
/*
@brief 打印支持的数据库类型
*/
static void printDrivers()const
{
xPrint<
class SshAdapter:public QObject
{
Q_OBJECT
public:
SshAdapter(QObject* parent=0);
void login(const QString& ipAddr,const QString& username,const QString& password);
void runCmd(const QString& cmd);
void cmdResult(const char* data);
void loginResult(bool result);
QSshManager* getSshManger()const;
private:
QSshManager *mSshManger;
int channelNo=-1; //表示渠道的序号
};
class UartDev : public QObject
{
Q_OBJECT
public:
explicit UartDev(QObject *parent = 0);
bool openCom(const QString com);
void closeCom() const;
void printComInfos();
void sendCmd(const QString& cmd);
signals:
private slots:
void onReadData();
private:
QSerialPort* mSerialPort;
};
static void MessageOutPut(QtMsgType type,const QMessageLogContext& context,const QString& msg)
{
Q_UNUSED(type)
Q_UNUSED(context)
static bool _printInfo = deBugOpen();
static QMutex mutex;
QMutexLocker locker(&mutex);
fprintf(stderr,"%s\n",msg.toLocal8Bit().data());
if(!_printInfo) return;
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
QString message = QString("%1 %2").arg(current_date_time).arg(msg);
QFile file(LOG_FILE);
file.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream text_stream(&file);
text_stream << message << "\r\n";
file.flush();
file.close();
}
XApplication::XApplication(const char* appName,int &argc, char **argv):QApplication(argc,argv)
{
#ifdef QT_NO_DEBUG
QBreakpadInstance.setDumpPath("crashs");
#endif
checkOnly(appName);
qInstallMessageHandler(MessageOutPut);
setApplicationName("XZPCode");
setApplicationVersion("1.0.0.1");
setOrganizationName("new thinging studio.std");
setOrganizationDomain("www.baidu.org");
}
XApplication::~XApplication()
{
xPrint;
}
void XApplication::checkOnly(const char* appName)
{
if(multOpen()) return;
// 创建互斥量
HANDLE m_hMutex = CreateMutex(NULL, FALSE, LPCWSTR(appName));
// 检查错误代码
if (GetLastError() == ERROR_ALREADY_EXISTS) {
// 如果已有互斥量存在则释放句柄并复位互斥量
CloseHandle(m_hMutex);
m_hMutex = NULL;
// 程序退出
exit(0);
}
}
整理中。。。。。。
整理中。。。。。。
整理中。。。。。。
代码地址:https://gitee.com/xzpblog/Qt-application-library