简单的QT进程间通信QCOP(2)
来源:互联网 发布:华为工业级网络路由器 编辑:程序博客网 时间:2024/06/05 11:27
#ifndef CEL_H
#define CEL_H
#include <QWidget>
class QSlider;
class QHBoxLayout;
class Cel : public QWidget
{
Q_OBJECT
public:
Cel();
~Cel() {};
private slots:
void handleMsg(const QString &message, const QByteArray &data);
void sendMsg(int celNum); //槽
private:
void fahToCel(int fahNum);
void createScreen();
void createCel();
void listenChannel();
QSlider* slider;
QHBoxLayout* celLayout;
};
//Cel.cpp
#endif //CEL_H
#include <QPushButton>
#include <QSlider>
#include <QLabel>
#include <QLCDNumber>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QApplication>
#include <QCopChannel>
#include <QDataStream>
#include <QByteArray>
#include "Cel.h"
Cel::Cel() : QWidget()
{
createScreen();
listenChannel();
}
void Cel::createScreen()
{
QPushButton* quitBtn = new QPushButton("Quit");
createCel();
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(quitBtn);
mainLayout->addLayout(celLayout);
setLayout(mainLayout);
slider->setFocus();
connect(quitBtn, SIGNAL(clicked()), qApp, SLOT(quit()));
setWindowTitle("Celsius");
}
void Cel::createCel()
{
slider = new QSlider(Qt::Vertical);
slider->setRange(0, 100);
slider->setValue(0);
slider->setTickPosition(QSlider::TicksLeft);
QLabel* celLabel = new QLabel("0");
celLayout = new QHBoxLayout;
celLayout->addWidget(celLabel, 0, Qt::AlignRight);
celLayout->addWidget(slider, 0, Qt::AlignLeft);
celLayout->setSpacing(10);
connect(slider, SIGNAL(valueChanged(int)), celLabel, SLOT(setNum(int)));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sendMsg(int)));
}
void Cel::fahToCel(int fahNum)
{
int celNum = (fahNum - 32) * 5 / 9;
slider->setValue(celNum);
}
void Cel::listenChannel()
{
QCopChannel *channel = new QCopChannel("/System/Temperature", this);//注册Channel
connect(channel, SIGNAL(received(const QString &, const QByteArray &)),
this, SLOT(handleMsg(const QString &, const QByteArray &)));
}
void Cel::handleMsg(const QString &message, const QByteArray &data)//处理收到信息
{
QDataStream in(data);
if (message == "ConvertFahToCel(int)")
{
int fahNum;
in >> fahNum;
fahToCel(fahNum);
}
}
void Cel::sendMsg(int celNum) //发送信息
{
QByteArray data;
QDataStream out(&data, QIODevice::WriteOnly);
out << celNum;
QCopChannel::send("/System/Temperature", "ConvertCelToFah(int)", data);
}
#include <QApplication>
#include "Cel.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv/*, QApplication::GuiClient*/);
Cel screen;
screen.setGeometry(0, 25, 100, 250);
screen.show();
return app.exec();
}
- 简单的QT进程间通信QCOP(2)
- 简单的QT进程间通信QCOP(1)
- Qt进程间的通信
- QT的进程间通信
- QT的进程间通信
- Linux进程间通信(简单的消息队列通信)
- qt 进程间通信
- QT进程间通信
- QT进程间通信
- QT-进程间通信
- Qt进程间通信
- Qt 学习之路 2(70):进程间通信
- Qt 进程间通信(IPC)
- Qt 进程间通信(IPC)
- Qt 进程间通信(IPC)
- Qt之进程间通信(IPC)
- Qt之进程间通信(QProcess)
- Qt 进程间通信(IPC)
- Solaris10控制台出现大量“Ping timeout”错误
- (1) PowerShell Web Access: Create PowerShell Web Access on Server 8
- PLSQL Developer连接不上Oracle11g X64
- jquery 调用 后台 asp.net
- ASN.1 (from 维基百科)
- 简单的QT进程间通信QCOP(2)
- Tomcat配置数据源(JNDI方式)
- 网站备份
- 解决Linux系统磁盘空间满的"软"办法
- 社会化推荐系统浅析-社会化推荐系统和传统搜索的区别及当前现状随谈
- TreeSet的使用。
- Java入门级题目及源代码(上)
- OpenGL反走样/抗锯齿实例
- android输入法框架整理