I have connected my QDBusConnection to a slot and I am sure it is connected because connect functions return True and i can see "connected to slot" log on console.
if ( m_bus.connect("com.mypage.MyService"
, "/MyRadio"
, "org.freedesktop.DBus.Properties"
, "PropertiesChanged"
, this
, SLOT(updateProperties(QString, QMap<QString, QVariant>))
)) {
qWarning() << "connected to slot";
}
But i cannot get any updates from corresponding dbus service. I am watching the service with dbus-monitor and am sure about signal is emitting.
the signal has following type :
<signal name="PropertiesChanged">
<arg type="s" name="interface_name"/>
<arg type="a{sv}" name="changed_properties"/>
<arg type="as" name="invalidated_properties"/>
</signal>
If i add a third argument to Slot like QList<QString> then it cannot connect properly ("connected the slot" sentence cannot be seen).
Any clue about why this is not working properly ?
The problem has solved after adding
qDBusRegisterMetaType<QMap<QString, QVariant>>();
So it was a simple error afterall.
Related
I'm using Ubuntu 18.04.
How do I retrieve the name of the WiFi that the system is connected to. So far I'm querying with the following but it is returning interface names instead of Wifi names:
QNetworkConfigurationManager nwkMgr;
QList<QNetworkConfiguration> nwkCnfList = nwkMgr.allConfigurations();
for(const QNetworkConfiguration &ncnf : nwkCnfList)
{
qDebug() << ncnf.name() << ncnf.bearerType();
if (ncnf.bearerType() == QNetworkConfiguration::BearerWLAN)
{
// would like to detect WiFi here
qDebug() << "WiFi:" << ncnf.name();
}
}
This lists the interfaces:
"Wired connection 1" 1
"ens33" 1
How can I get the NAME of the Wifi?
Can you use system variables ? If so do this:
export WNAME=$(iw dev | grep ssid | awk '{print $2}')
It will export it to a variable WNAME and you can use it inside scripts untill you logout or shutdown the system.
I created a reproduction sample for this:
#include <iostream>
#include <QtCore/QLoggingCategory>
#include <QtCore/QDebug>
#include <QtCore/QtCore>
using namespace std;
int main () {
int i;
QLoggingCategory::setFilterRules("*.debug=true\n");
QLoggingCategory LogO(NULL);
if (LogO.isDebugEnabled()) {
cout << "QDebug enabled\n";
} else {
cout << "QDebug disabled!\n";
}
cout << "Start!\n";
qDebug() << "qStart!";
cerr << "print to stderr.\n";
qWarning() << "qWarning";
return 0;
}
Build steps:
g++ -c -fPIC -I/usr/include/qt5 main.cpp -o main.o
g++ -fPIC main.o -L /usr/lib64 -lQt5Core -o testapp
When executing the application in an interactive shell, output redirection works as expected:
Setup:
./testapp > out 2> err
Output:
>>cat out:
QDebug enabled
Start!
>>cat err:
qStart!
print to stderr.
qWarning
However, it does not work if the application is executed as a cronjob, the output of qDebug() and qWarning() is missing:
Setup:
* * * * * username /home/username/temp/build/testapp 1> /home/username/temp/log/out 2> /home/username/temp/log/err
Output:
>>cat /home/username/temp/log/out
QDebug enabled
Start!
>>cat home/username/temp/log/err
print to stderr.
Enviroment vars
The output of env in the interative shell is as follows:
LS_COLORS=*long string*
SSH_CONNECTION=*censored*
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
HOSTNAME=*censored*
XDG_SESSION_ID=492
USER=username
SELINUX_ROLE_REQUESTED=
PWD=/home/username/temp/build
HOME=/home/username
SSH_CLIENT=*censored*
SELINUX_LEVEL_REQUESTED=
SSH_TTY=/dev/pts/0
MAIL=/var/spool/mail/username
TERM=xterm
SHELL=/bin/bash
SELINUX_USE_CURRENT_RANGE=
SHLVL=1
LOGNAME=username
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
XDG_RUNTIME_DIR=/run/user/1000
PATH=/usr/lib64/ccache:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/username/.local/bin:/home/username/bin
HISTSIZE=1000
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/usr/bin/env
OLDPWD=/home/username/temp/build/logs
The output of env when called via cronjob is as follows:
LS_COLORS=*long string*
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
HOSTNAME=*censored*
XDG_SESSION_ID=995
USER=username
PWD=/home/username
HOME=/home/username
MAIL=/var/spool/mail/username
TERM=xterm
SHELL=/bin/bash
SHLVL=1
LOGNAME=username
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
XDG_RUNTIME_DIR=/run/user/1000
PATH=/usr/lib64/ccache:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/username/.local/bin:/home/username/bin
LESSOPEN=||/usr/bin/lesspipe.sh %s
_=/usr/bin/env
The issue is that qt behaves differently depending if it thinks that it is running in an (interactive?) terminal or not.
Quote:
One pitfall to be aware of: the destination of logging depends on an environment variable. If the variable QT_LOGGING_TO_CONSOLE is set to 1, the message functions will always log to the console. If set to 0, they will not log to the console, and will instead log to syslog, if enabled. When the environment variable is not set, the message functions log to a console if one is present (i.e. if the program is attached to a terminal). Thus, to ensure that the output of our example program goes to syslog, I set the environment variable to 0 within the program.
Therefore, the output of qDebug, QWarning etc. when executed from cron was not output via stderr, but directly handed over to journald.
TL;DR: quickfix: add QT_LOGGING_TO_CONSOLE=1 to /etc/crontab
.
.
PS: note if you need to debug an issue with QDebug:
be aware of this: https://bugzilla.redhat.com/show_bug.cgi?id=1227295
you can add QT_LOGGING_DEBUG=1 as an environment variable to make
qt output changes in logging behavior during execution.
cronjob redirects output and err to email address.
add >> /tmp/myscript.log 2>&1 in your crontab entry.
see this answer
Qt5.3 sees the default Raspberry Pi also_output.0.analog-mono device ( 3.5 mm headphone jack ) and QAudioOutput from 5.3 successfully writes audio to that device and I can hear the audio with my headphones. This all works with default Raspbian, with PulseAudio 2.0 from apt-get, and no extra configuration. PulseAudio is run as session process and not in the System Daemon mode. Qt 5.4 does not see the device with the exact same source code and Raspbian ( except cross-compiled with Qt 5.4.0 and not Qt 5.3.2 ) and also cannot write data to it.
It gives me this error ( Please note that I've manually assigned both sys default:CARD=ALSA and 'default' but they both return the same 'snd_pcm_hw_params' error ):
Output Device name: "sysdefault:CARD=ALSA"
Output Device name: "default"
Default device is "default"
Output device is: "default"
"QAudioOutput: snd_pcm_hw_params: err = -12"
Pactl sees it:
pactl list sinks
Sink #0
State: SUSPENDED
Name: alsa_output.0.analog-mono
Description: bcm2835 ALSA Analog Mono
Driver: module-alsa-card.c
Sample Specification: u8 1ch 8000Hz
I've tried to modify /etc/pulse/default.pa with this at the bottom to force the output device:
load-module module-alsa-sink sink_name=alsa_output.0.analog-mono device=hw:0
set-default-sink alsa_output.0.analog-mono
Here is my setup code that gives the error:
// Coordinator receives Audio data
m_Format.setSampleRate(8000);
m_Format.setChannelCount(1);
m_Format.setSampleSize(8);
m_Format.setCodec("audio/pcm");
m_Format.setByteOrder(QAudioFormat::BigEndian);
m_Format.setSampleType(QAudioFormat::UnSignedInt);
QAudioDeviceInfo infoOut(QAudioDeviceInfo::defaultOutputDevice());
foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
qDebug() << "Output Device name: " << deviceInfo.deviceName();
}
qDebug() << "Default device is" << infoOut.deviceName();
if (!infoOut.isFormatSupported(m_Format))
{
qDebug()<< "Default format not supported - trying to use nearest";
m_Format = infoOut.nearestFormat(m_Format);
}
qDebug() << "Output device is: " << infoOut.deviceName();
m_AudioOutput = new QAudioOutput(infoOut, m_Format, this);
// This data accumulates and dumps data to output
m_DataForOutput.clear();
// Now Start playing
// m_Output gets written to to send data to speakers
m_Output = m_AudioOutput->start();
What in the world is going on? How come the same configuration works with 5.3.2 and not 5.4.1. Assigning the default audio device doesn't work... What can I do here and how can I make it work? Thanks!
The answer was to run in session mode ( not a system-wide PulseAudio daemon ) and edit default.pa to look like this:
## Create the default output device
#load-module module-udev-detect tsched=0
load-module module-alsa-card device_id=0
#load-module module-alsa-card device_id=0 tsched=0 fragments=10 fragment_size=640 tsched_buffer_size=4194384 tsched_buffer_watermark=262144
#load-module module-alsa-card device_id=0 tsched=0 fragments=6 fragment_size=16 tsched_buffer_size=4194384 tsched_buffer_watermark=262144
load-module module-suspend-on-idle timeout=86400
### Load several protocols
load-module module-native-protocol-unix
### Make sure we always have a sink around, even if it is a null sink.
#load-module module-always-sink
I want to launch a shell script with Qt.
QProcess process;
process.start(commandLine, QStringList() << confFile);
process.waitForFinished();
if(process.exitCode()!=0)
{
qDebug () << " Error " << process.exitCode() << process.readAllStrandardError();
}
else
{
qDebug () << " Ok " << process.readAllStrandardOutput() << process.readAllStrandardError();
}
The result is :
Ok : Result.... " "" QProcess : Destroyed while process is still
running.
This message does not appear every time.
What is the problem?
process.waitForFinished(); is hitting the default 30 seconds timeout. Use process.waitForFinished(-1); instead. This will make sure you wait for however long it takes for the process to finish, without any timeout.
Note you create QProcess into the local scope. This means that the object will be deleted when you exit the scope. In the destructor QProcess process terminates. The message "Destroyed" while "the process is still running" when the process terminates in the destructor.
For solving this problem, you should call QProcess destructor when process is already terminated.
If will be QProcess::waitForFinished(-1) into your example, it will occur, but this will block you application.
I'm trying to use CoreMIDI in a RubyMotion project. Here's a simple example of the code:
clientName = "Client"
clientRef = Pointer.new(:uint)
MIDIClientCreate( clientName, nil, nil, clientRef )
See more detailed code and backtrace in the following gist: https://gist.github.com/4299810
That code results in the following error:
(main)> 2012-12-15 14:43:27.410 core-midi-test[42560:c07]
app_delegate.rb:5:in application:didFinishLaunchingWithOptions:':
expected instance of Pointer of type^{OpaqueMIDIClient}', got I'
(TypeError) 2012-12-15 14:43:27.412 core-midi-test[42560:c07] ***
Terminating app due to uncaught exception 'TypeError', reason:
'app_delegate.rb:5:inapplication:didFinishLaunchingWithOptions:':
expected instance of Pointer of type ^{OpaqueMIDIClient}', gotI'
(TypeError)'
The error is apparently with the fourth argument to MIDIClientCreate. The docs for MIDIClientCreate show:
OSStatus MIDIClientCreate (
CFStringRef name,
MIDINotifyProc notifyProc,
void *notifyRefCon,
MIDIClientRef *outClient
);
MIDIClientRef derives from MIDIObjectRef which is defined as a UInt32, so I'm fairly certain that Pointer.new(:uint) is the correct type to use with RubyMotion.
Here is the pertinent portion of the CoreMIDI.bridgesupport file that RubyMotion is using:
<function name='MIDIClientCreate'>
<arg name='name' type='^{__CFString=}' declared_type='CFStringRef'/>
<arg name='notifyProc' function_pointer='true' type='^?' declared_type='MIDINotifyProc'>
<arg type='^{MIDINotification=iI}' declared_type='MIDINotification*' const='true'/>
<arg type='^v' declared_type='void*'/>
<retval type='v' declared_type='void'/>
</arg>
<arg name='notifyRefCon' type='^v' declared_type='void*'/>
<arg name='outClient' type='^^{OpaqueMIDIClient}' declared_type='MIDIClientRef*'/>
<retval type='l' declared_type='OSStatus'/>
</function>
As far as I can tell, the bridgesupport definition should include the necessary plumbing to make the proper conversion. But it's of course, not working.
Is there something wrong with my code or is there something wrong the CoreMIDI.bridgesupport file included with RubyMotion?
I found out by reading the documentation for MacRuby that one can explicitly pass the desired pointer type to the Pointer constructor like so:
clientName = "Client"
clientRef = Pointer.new(MIDIClientRef.type)
MIDIClientCreate( clientName, nil, nil, clientRef )
portName = "Output"
outport = Pointer.new(MIDIPortRef.type)
MIDIOutputPortCreate( clientRef[0], portName, outport )