Re: [Interest] QtCreator >= 6 - Problems using code indentation shift with tab key

2022-04-14 Thread Kevin André
Hi,

Op wo 13 apr. 2022 om 17:26 schreef Nuno Santos :
> Since Qt Creator 6.0 I’m unable to indent shit code with tab more than one 
> time. After one indentation with tab, code gets deselected. This happens with 
> shift+tab as well.
>
> Is anyone else having the same problem? Is this some kind of non default 
> behaviour that changed?

I can confirm this. It happens when more than one line is selected and
shift-tab is used to move those lines to the left. (Not sure if moving
to the right has the same problem.) This is annoying when you want to
change indentation with more than one level.


Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Detecting system power events

2021-09-17 Thread Kevin André
Hi,

Op wo 15 sep. 2021 om 20:53 schreef Marius Kittler :
>
> I'm not aware of a cross-platform way. On a systemd-based system you can
> easily use its D-Bus interface via Qt DBus: https://www.freedesktop.org/
> software/systemd/man/org.freedesktop.login1.html#Signals
>
> You can check https://github.com/Martchus/syncthingtray/blob/master/connector/
> syncthingservice.cpp for an example.

Thanks.
But I am reluctant to write platform-specific code. I can only
realistically write code for the platform(s) that I use myself,
because that code needs to be tested by me first. However, I guess I
will have no choice, as expecting a cross-platform solution to
suddenly appear is not realistic :-)

> However, I'd also be interested in a cross-platform solution or at least some
> implementations of this for further platforms within the context of a Qt
> application. Under Windows it is likely just some WinAPI function but I
> haven't taken the time to look into it.

I have created a feature request for a cross-platform solution in Qt:
QTBUG-96637
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] Detecting system power events

2021-09-15 Thread Kevin André
Hi,

I am developing a client-server music player, and I would like to
detect when the server machine enters sleep mode or when it shuts
down. When those events occur I would like the server to pause/stop
playback, send a notification to all clients that are connected at
that time and then close all open TCP connections.

A shutdown can be detected using the "aboutToQuit" signal, but I could
not find anything regarding sleep. Will I need to write
platform-specific code for this (using QAbstractNativeEventFilter) or
is there a better way?

Ideally I would like to be able to distinguish between a shutdown and
the system going to sleep, so I can send a slightly different
notification to the clients. It is useful to know the difference in
the client, because a shutdown implies a permanent disconnect while
sleep means that the client could try to reconnect to the server again
later as soon as it detects its presence again.

The problem I'm having now is the server machine going to sleep while
the client that is running on another machine remains unaware as long
as it does not try to send some kind of request to the server.


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] HiDPI issues

2021-09-12 Thread Kevin André
Hi,

I am trying to follow the "long term" advice here:
https://doc.qt.io/qt-5/highdpi.html
This means that I don't set any attributes or environment variables
regarding HiDPI, and that I try to use widget sizes that are
"calculated from font metrics or screen size".

One example, a custom widget that used to have a hardcoded size. The
widget was too small on the 4K screen of my new laptop (scaling factor
in Windows set to 250%), so I changed it as follows:

QSize ColorSwitcher::minimumSizeHint() const
{
auto size = desiredSize();
return QSize(size, size);
}

QSize ColorSwitcher::sizeHint() const
{
return minimumSizeHint();
}

qreal ColorSwitcher::desiredSize() const
{
QFontMetricsF metrics { font() };
return metrics.height() * 0.8;
}

But when I run this code, the widget is even smaller than with the
hardcoded size it used to have. Then when I move the application
window to the other monitor and back again (shift-win-arrow keys), the
size of the widget is suddenly what it should be.

The other monitor is an external screen with classic DPI (scaling
factor set to 100%) and is the primary screen. It's as if the font
metrics operate on the wrong values until I force them to refresh
somehow by moving the application window across different screens.

I am having a similar problem with a few QLabel instances. Their size
is too small for their text content. The text has the right size, but
the size of the label looks like it has been calculated for the same
text with a much lower DPI. Moving the application window to the other
screen and back again fixes the size issue here as well. Most QLabels
don't have this problem, only those two that I insert at runtime are
misbehaving.

Just in case it is relevant, this is how I insert them:

// ClickableLabel is derived from QLabel; it uses mousePressEvent to
emit a clicked() signal
// static function, called to replace a placeholder label
ClickableLabel* ClickableLabel::replace(QLabel*& existingLabel)
{
auto* clickable = new ClickableLabel();
clickable->setText(existingLabel->text());
auto parent = existingLabel->parentWidget();
auto layoutItem = parent->layout()->replaceWidget(existingLabel, clickable);
delete layoutItem;
delete existingLabel;
existingLabel = clickable;
return clickable;
}

I use the "replace" trick because it is impractical to use custom
widgets in the designer.

So am I facing a bug in Qt, or am I doing something wrong here?
My Qt version is 5.15.2.


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Warning about QHash keys().toVector()

2021-06-14 Thread Kevin André
On Sun, Jun 13, 2021 at 10:35 PM André Pönitz  wrote:
>
> On Sun, Jun 13, 2021 at 06:20:31PM +0200, Kevin André wrote:
> >
> > I have the following piece of code:
> >
> > QVector CompatibilityInterfaceImpl::getActionIds() const
> > {
> > return _actions.keys().toVector();   // _actions is a QHash
> > }
> >
> > In Qt Creator this generates the following warning:
> >allocating an unneeded temporary container [clazy-container-anti-pattern]
> >
> > How can I avoid the warning in this case?
> >
> > I am using Qt 5.12, so I return a QVector instead of a QList because
> > using the old (Qt 5) QList is discouraged. Unfortunately many Qt API's
> > still use QList for nearly everything, so I am faced with a difficult
> > choice:
> >
> >   1) go back to using QList
>
> That would be my advice.

Well, I decided not to use QList because I like things to be
consistent and use QVector everywhere.

> While QList never was the atrocity some people wanted us to believe [1],
> you actually have one of the rare cases here were Q(5)Vector really
> takes less memory than Q(5)List on 64bit machines, roughly 4 bytes
> times the number of items in your _actions container.

I am currently using mingw 32-bit, does that make much of a difference
for the comparison?

In Qt 5, QList stores pointers to the elements while QVector stores
the elements directly, is that correct? In that case, wouldn't the
difference be 8 bytes times the element count if the element is a
64-bit int?

> But given that your application is apparently fine with using QHash::keys
> here it is safe to say that you will not observe any difference.

True. For this particular piece of code I even expect the number of
elements to be less than 10 most of the time :-)
But my question was more about what's the best practice.


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Warning about QHash keys().toVector()

2021-06-14 Thread Kevin André
On Sun, Jun 13, 2021 at 8:29 PM Konstantin Shegunov  wrote:
>
> On Sun, Jun 13, 2021 at 7:22 PM Kevin André  wrote:
>>
>> How can I avoid the warning in this case?
>
> return QVector<..>(_actions.keyBegin(), _actions.keyEnd());
>
> Should work, I believe.

This would have been my preferred solution. But that constructor was
introduced in Qt 5.14, and I am still using Qt 5.12.


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Warning about QHash keys().toVector()

2021-06-14 Thread Kevin André
On Sun, Jun 13, 2021 at 7:14 PM Thiago Macieira
 wrote:
>
> On Sunday, 13 June 2021 09:20:31 PDT Kevin André wrote:
> > I have the following piece of code:
> >
> > QVector CompatibilityInterfaceImpl::getActionIds() const
> > {
> > return _actions.keys().toVector();   // _actions is a QHash
> > }
> >
> > In Qt Creator this generates the following warning:
> >allocating an unneeded temporary container [clazy-container-anti-pattern]
> >
> > How can I avoid the warning in this case?
>
> Create the QVector container, reserve the proper size, and then iterate over
> the actions hashing table inserting the keys.

That's the "write my own conversion function" option I listed :-)

Since I already had a few existing conversion functions, I opted for
your solution:

template static QVector
keysToVector(QHash const& hash)
{
QVector v;
v.reserve(hash.size());

for (auto it = hash.keyBegin(); it != hash.keyEnd(); ++it)
v.append(*it);

return v;
}

QVector CompatibilityInterfaceImpl::getActionIds() const
{
return keysToVector(_actions);
}


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] Warning about QHash keys().toVector()

2021-06-13 Thread Kevin André
Hi,

I have the following piece of code:

QVector CompatibilityInterfaceImpl::getActionIds() const
{
return _actions.keys().toVector();   // _actions is a QHash
}

In Qt Creator this generates the following warning:
   allocating an unneeded temporary container [clazy-container-anti-pattern]

How can I avoid the warning in this case?

I am using Qt 5.12, so I return a QVector instead of a QList because
using the old (Qt 5) QList is discouraged. Unfortunately many Qt API's
still use QList for nearly everything, so I am faced with a difficult
choice:

  1) go back to using QList
  2) deal with warnings and/or write my own conversion functions that
are probably not very efficient

Or is there another (convenient) way to solve this that I am not aware of?
Migrating to Qt 6 is not an option right now.


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QVariant toBool() not working correctly?

2021-01-26 Thread Kevin André
Hi,

On Tue, Jan 26, 2021 at 5:38 PM Giuseppe D'Angelo via Interest
 wrote:

> You've been bit by a combination of two things, one is Qt not supporting
> the BIT column type natively (that's QTBUG-21326), and mapping it to a
> string. The other that the string you're getting contains a NUL
> (U+), not a literal 0 (U+0030). When converting a QVariant
> containing a string to bool, Qt maps empty strings, the string "0" and
> the string "false" (in any case) to false and everything else to true:
>
> > https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qvariant.cpp?h=5.12#n344

Thanks Christian and Giuseppe for your help.
I am now using the following workaround:

bool Database::getBool(QVariant v, bool nullValue)
{
if (v.isNull())
return nullValue;

/* workaround for zero BIT value being loaded as "\0" instead of "0" */
if (v == QVariant(QChar(0)))
return false;

return v.toBool();
}


Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] QVariant toBool() not working correctly?

2021-01-26 Thread Kevin André
Hi,

I am reading a boolean value from a database column with SQL type
"BIT" in MySQL. But I discovered that when a zero is stored in that
column, my program apparently interprets that zero value as a boolean
true value. I traced the problem to the QVariant->bool conversion:

bool Database::getBool(QVariant v, bool nullValue)
{
qDebug() << "getBool called for:" << v;
if (v.isNull())
return nullValue;

qDebug() << "getBool will convert" << v << "to bool" << v.toBool();
return v.toBool();
}

When reading a zero BIT value from the database, this outputs:

getBool called for: QVariant(QString, "\u")
getBool will convert QVariant(QString, "\u") to bool true

The docs of toBool() claim that toBool should return false for a
string value of "0".
I am using Qt version 5.12.3.
So is this a mismatch between the Qt version of the docs and the Qt
version that I am using? Or am I missing something else here?


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QMediaPlayer and Bluetooth speaker stuttering

2020-06-25 Thread Kevin André
On Wed, Apr 29, 2020 at 1:54 AM Kevin André  wrote:
> My music player uses QMediaPlayer to play MP3 files, which works fine
> when listening through headphones. But when I use a Bluetooth speaker,
> the sound stutters, and the song sounds slow. Almost like the data is
> sent to the speaker too slowly, and the speaker pauses playback when
> the buffer is empty, and resumes briefly when it receives some more
> data, then pauses again and so on.

Update:
The problem no longer occurs after installing the latest Windows
feature update (2004).
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] how to get 3 pixel focus ring?

2020-06-09 Thread Kevin André
Just speculating without really knowing anything about this, but...

Have you made sure that there actually is enough space for painting
that focus ring?
Up until now I had never heard of a "focus ring", but after looking at
the screenshots, it seems that it is simply a wide border around a
widget that is only visible when the widget has focus. But if a widget
was not designed to have such a large border around it, there might
simply be no room around the widget to paint your focus ring and then
anything you try to paint might simply be completely or partially lost
by clipping. This could explain why your experiments show a partial
result on Mac but no result at all on Windows; Qt might put some extra
space around widgets on Mac but not on Windows just because both
platforms have their own style that Qt tries to mimic.



On Sun, Jun 7, 2020 at 11:21 PM David M. Cotter  wrote:
>
> i have an example project (see below), that tries 6 different 
> implementations, attempts to make the focus ring 3 pix wide. None of them 
> work on windows, and only one of them PARTIALLY works on mac. What i want is 
> the style you get around a text edit on mac, but i want that style on ALL 
> widgets, and i want it on windows too.
>
> anyone have any idea how i can accomplish this?
>
> Please see the example project. I've set it up so the same code can be run on 
> both mac and windows (use file sharing to run both at once).
>
> thanks
>
> -dave
> ___
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] QMediaPlayer and Bluetooth speaker stuttering

2020-04-28 Thread Kevin André
Hi,

My music player uses QMediaPlayer to play MP3 files, which works fine
when listening through headphones. But when I use a Bluetooth speaker,
the sound stutters, and the song sounds slow. Almost like the data is
sent to the speaker too slowly, and the speaker pauses playback when
the buffer is empty, and resumes briefly when it receives some more
data, then pauses again and so on.

One might assume that it is a hardware issue, but the problem only
occurs with my music player and not when playing music through other
means, like YouTube in a web browser.

After struggling with this problem for a long time, I discovered that
the problem can be fixed temporarily by running the Bluetooth
troubleshooter (Windows 10: settings -> update & security ->
troubleshoot -> Bluetooth). This utility only seems to reset the
Bluetooth connection somehow, but after running it I can play music
again just fine. Until I turn off the speaker and turn it back on.
Then the problem is back (most of the time).

As far as I remember, the problem didn't exist in the very beginning.
I think it first manifested itself after some update of Windows, but
I'm not sure, it's been a long time since.

I am currently using Qt version 5.12.3, but the problem first appeared
when I was still using an older version.

Does anyone else have the same issue? Any idea what might be causing this?


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] Keep screen active on desktop

2020-02-05 Thread Kevin André
On Sun, Dec 29, 2019 at 3:41 PM Kevin André  wrote:
> Does Qt provide some platform-independent way to keep the screen
> active? Or do I need to submit an enhancement request?

I have created an enhancement request for this:

https://bugreports.qt.io/browse/QTBUG-81907
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] Keep screen active on desktop

2019-12-29 Thread Kevin André
Hi,

I'm developing a FOSS music player (using Qt Widgets), and when I run
it on my company laptop, after about 15 minutes of user inactivity
(not touching the keyboard or mouse) the screen turns off and the
Windows session is locked. But I've checked the screensaver setting,
and screensaver is disabled. So I'm guessing that this is a security
measure configured by my employer using Group Policy. But other
programs like VLC don't seem to suffer from this problem, so they must
have some mechanism for preventing this.

I did some searching, and I know that on Windows, for example,
periodic calls to SendInput() can be used to simulate user activity
and prevent screensaver activation. But I would like to avoid having
to write platform specific code.

Does Qt provide some platform-independent way to keep the screen
active? Or do I need to submit an enhancement request?


Thanks,

Kevin
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest