本文整理汇总了C++中QDBusInterface::property方法的典型用法代码示例。如果您正苦于以下问题:C++ QDBusInterface::property方法的具体用法?C++ QDBusInterface::property怎么用?C++ QDBusInterface::property使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDBusInterface
的用法示例。
在下文中一共展示了QDBusInterface::property方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: requeryDevice
void DBusConnector::requeryDevice (const QString& id)
{
QDBusInterface face ("org.freedesktop.UPower",
id,
"org.freedesktop.UPower.Device",
SB_);
if (face.property ("Type").toInt () != 2)
return;
BatteryInfo info;
info.ID_ = id;
info.Percentage_ = face.property ("Percentage").toInt ();
info.TimeToFull_ = face.property ("TimeToFull").toLongLong ();
info.TimeToEmpty_ = face.property ("TimeToEmpty").toLongLong ();
info.Voltage_ = face.property ("Voltage").toDouble ();
info.Energy_ = face.property ("Energy").toDouble ();
info.EnergyFull_ = face.property ("EnergyFull").toDouble ();
info.DesignEnergyFull_ = face.property ("EnergyFullDesign").toDouble ();
info.EnergyRate_ = face.property ("EnergyRate").toDouble ();
info.Technology_ = TechIdToString (face.property ("Technology").toInt ());
info.Temperature_ = 0;
emit batteryInfoUpdated (info);
}
示例2: main
int main(int argc, char *argv[])
{
// TODO: Clean this up, update API, etc.
if (argc < 5 || argc > 6)
{
qWarning() << "Error detected! Insufficient number of arguments.";
qWarning() << "";
qWarning() << "Usage: ambdbusaccess <R/W> <Object> <Property> <Zone> [Value]";
qWarning() << "- <R/W>";
qWarning() << " Used for specifying [R]ead or [W]rite.";
qWarning() << "- <Object>";
qWarning() << " The AMB object to access.";
qWarning() << "- <Property>";
qWarning() << " The property within the object to access.";
qWarning() << "- <Zone>";
qWarning() << " The AMB zone to access.";
qWarning() << "- [Value]";
qWarning() << " The value to write, if writing.";
qWarning() << "Example: ambdbusaccess Write ClimateControl FanSpeedLevel 0 7";
qWarning() << "";
qWarning() << "This program returns an int under the following conditions:";
qWarning() << "Successful Read: <Value Read>";
qWarning() << "Unsuccessful Read: -1";
qWarning() << "Successful Write: <Value Written>";
qWarning() << "Unsuccessful Write: -1";
return -1;
}
// TODO: Error check input.
bool read = !strncmp(argv[1], "R", 1);
QString object = argv[2];
QString property = argv[3];
qint32 zone = atoi(argv[4]);
qint32 value = 0;
if (argc == 6)
{
value = atoi(argv[5]);
}
// Necessary to suppress Qt messages about touching the D-Bus before the application was created.
QCoreApplication a(argc, argv);
// Sanity check that the system bus is actually present.
if (!QDBusConnection::systemBus().isConnected())
{
qCritical() << "Could not access system D-Bus!";
return -1;
}
// Get ahold of the manager object.
QDBusInterface *manager = new QDBusInterface("org.automotive.message.broker", "/", "org.automotive.Manager",
QDBusConnection::systemBus());
// Go fetch the path for the AMB object we are concerned with.
qDebug().nospace() << "Looking for property " << property.toStdString().c_str() << " of object " <<
object.toStdString().c_str() << " in zone " << zone << ".";
QDBusReply<QDBusObjectPath> propertyPath = manager->call("FindObjectForZone", object.toStdString().c_str(), zone);
if (!propertyPath.isValid())
{
qDebug() << "Invalid reply!" << propertyPath.error() << "Got the path:" << propertyPath.value().path();
}
// Now that we have the path, open an interface to the object.
QDBusInterface *propertyInterface = new QDBusInterface("org.automotive.message.broker", propertyPath.value().path(),
"org.automotive.ClimateControl", QDBusConnection::systemBus());
// Perform our read or write operation.
if (read)
{
QVariant reply = propertyInterface->property(property.toStdString().c_str());
if (!reply.isValid())
{
qDebug() << "Invalid reply when reading the property!" << propertyInterface->lastError() << "Property:" <<
reply.toString();
value = -1;
}
else
{
qDebug().nospace() << "Got a valid reply for the property of " << reply.toString().toStdString().c_str() << ".";
value = reply.toInt();
}
}
else
{
QVariant reply = propertyInterface->setProperty(property.toStdString().c_str(), value);
if (reply.toBool())
{
qDebug() << "Successfully wrote the property.";
}
else
{
qDebug() << "Failed to write the property.";
value = -1;
}
}
// Clean up.
delete propertyInterface;
//.........这里部分代码省略.........
示例3: data
QVariant UnitModel::data(const QModelIndex & index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole)
{
if (index.column() == 0)
return unitList->at(index.row()).load_state;
else if (index.column() == 1)
return unitList->at(index.row()).active_state;
else if (index.column() == 2)
return unitList->at(index.row()).sub_state;
else if (index.column() == 3)
return unitList->at(index.row()).id;
}
else if (role == Qt::ForegroundRole)
{
const KColorScheme scheme(QPalette::Normal);
if (unitList->at(index.row()).active_state == "active")
return scheme.foreground(KColorScheme::PositiveText);
else if (unitList->at(index.row()).active_state == "failed")
return scheme.foreground(KColorScheme::NegativeText);
else if (unitList->at(index.row()).active_state == "-")
return scheme.foreground(KColorScheme::InactiveText);
else
return QVariant();
}
else if (role == Qt::ToolTipRole)
{
QString selUnit = unitList->at(index.row()).id;
QString selUnitPath = unitList->at(index.row()).unit_path.path();
QString selUnitFile = unitList->at(index.row()).unit_file;
QString toolTipText;
toolTipText.append("<FONT COLOR=white>");
toolTipText.append("<b>" + selUnit + "</b><hr>");
// Create a DBus interface
QDBusConnection bus("");
if (!userBus.isEmpty())
bus = QDBusConnection::connectToBus(userBus, "org.freedesktop.systemd1");
else
bus = QDBusConnection::systemBus();
QDBusInterface *iface;
// Use the DBus interface to get unit properties
if (!selUnitPath.isEmpty())
{
// Unit has a valid path
iface = new QDBusInterface ("org.freedesktop.systemd1",
selUnitPath,
"org.freedesktop.systemd1.Unit",
bus);
if (iface->isValid())
{
// Unit has a valid unit DBus object
toolTipText.append(i18n("<b>Description: </b>"));
toolTipText.append(iface->property("Description").toString());
toolTipText.append(i18n("<br><b>Unit file: </b>"));
toolTipText.append(iface->property("FragmentPath").toString());
toolTipText.append(i18n("<br><b>Unit file state: </b>"));
toolTipText.append(iface->property("UnitFileState").toString());
qulonglong ActiveEnterTimestamp = iface->property("ActiveEnterTimestamp").toULongLong();
toolTipText.append(i18n("<br><b>Activated: </b>"));
if (ActiveEnterTimestamp == 0)
toolTipText.append("n/a");
else
{
QDateTime timeActivated;
timeActivated.setMSecsSinceEpoch(ActiveEnterTimestamp/1000);
toolTipText.append(timeActivated.toString());
}
qulonglong InactiveEnterTimestamp = iface->property("InactiveEnterTimestamp").toULongLong();
toolTipText.append(i18n("<br><b>Deactivated: </b>"));
if (InactiveEnterTimestamp == 0)
toolTipText.append("n/a");
else
{
QDateTime timeDeactivated;
timeDeactivated.setMSecsSinceEpoch(InactiveEnterTimestamp/1000);
toolTipText.append(timeDeactivated.toString());
}
}
delete iface;
}
else
{
// Unit does not have a valid unit DBus object
// Retrieve UnitFileState from Manager object
iface = new QDBusInterface ("org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
//.........这里部分代码省略.........