Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building on Qt 5.15 #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")

# Find the QtWidgets library
find_package(Qt5Widgets)
find_package(Qt5 COMPONENTS Widgets SerialPort Network Svg REQUIRED)

# If set, cmake will download Qwt over SVN, build and use it as a static library.
set(BUILD_QWT true CACHE BOOL "Download and build Qwt automatically.")
Expand Down Expand Up @@ -146,7 +146,7 @@ add_executable(${PROGRAM_NAME} WIN32
target_link_libraries(${PROGRAM_NAME}
${QWT_LIBRARY}
)
qt5_use_modules(${PROGRAM_NAME} Widgets SerialPort Network Svg)
target_link_libraries(${PROGRAM_NAME} Qt5::Widgets Qt5::SerialPort Qt5::Network Qt5::Svg)

if (BUILD_QWT)
add_dependencies(${PROGRAM_NAME} QWT)
Expand Down
2 changes: 1 addition & 1 deletion src/asciireader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ unsigned AsciiReader::readData()

SamplePack* AsciiReader::parseLine(const QString& line) const
{
auto separatedValues = line.split(delimiter, QString::SkipEmptyParts);
auto separatedValues = line.split(delimiter, Qt::SkipEmptyParts);
unsigned numComingChannels = separatedValues.length();

// check number of channels (skipped if auto num channels is enabled)
Expand Down
2 changes: 1 addition & 1 deletion src/asciireadersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ AsciiReaderSettings::AsciiReaderSettings(QWidget *parent) :
});

connect(&filterButtons,
SELECT<int, bool>::OVERLOAD_OF(&QButtonGroup::buttonToggled),
SELECT<int, bool>::OVERLOAD_OF(&QButtonGroup::idToggled),
[this](int id, bool checked)
{
emit filterChanged(static_cast<FilterMode>(id), ui->leFilterPrefix->text());
Expand Down
2 changes: 2 additions & 0 deletions src/barchart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/

#include <QPalette>
#include <QwtText>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this one? This include fails when compiling with Qt5.15 and Qwt 6.1.6 (built by project).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <qwt_text.h> works.

#include <qwt_scale_map.h>
#include <qwt_math.h>

#include "barchart.h"

Expand Down
4 changes: 2 additions & 2 deletions src/commandpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
CommandPanel::CommandPanel(QSerialPort* port, QWidget *parent) :
QWidget(parent),
ui(new Ui::CommandPanel),
_menu(trUtf8("&Commands")), _newCommandAction(trUtf8("&New Command"), this)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that trUtf8 is deprecated. But is there a reason to not use tr as well?

_menu("&Commands"), _newCommandAction("&New Command", this)
{
serialPort = port;

Expand Down Expand Up @@ -55,7 +55,7 @@ CommandWidget* CommandPanel::newCommand()
{
auto command = new CommandWidget();
command_name_counter++;
command->setName(trUtf8("Command ") + QString::number(command_name_counter));
command->setName("Command " + QString::number(command_name_counter));
ui->scrollAreaWidgetContents->layout()->addWidget(command);
command->setFocusToEdit();
connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand);
Expand Down
2 changes: 1 addition & 1 deletion src/framedreadersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ FramedReaderSettings::FramedReaderSettings(QWidget *parent) :
fbGroup.addButton(ui->rbSize1Byte, (int) SizeFieldType::Field1Byte);
fbGroup.addButton(ui->rbSize2Byte, (int) SizeFieldType::Field2Byte);

connect(&fbGroup, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems (int,bool) overload of buttonToggled is deprecated. But idToggled is only added at 5.15. I would prefer the buttonToggled(QAbstractButton *button, bool checked) signal which is still supported in 5.15 and already exists in older versions. Sorry I can't say a reason off the top of my head, but I try to support down to 5.9.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason was that Qt5.9 is the version that comes with the Ubuntu 18.04. I try to support the oldest LTS version of the Ubuntu that I can.

I know that it is not difficult to install any Qt version on Ubuntu, but when things works out of the box, it is very helpful for new comers.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record; latest ubuntu LTS 20.04 comes with the Qt 5.12.

connect(&fbGroup, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::idToggled),
[this](int id, bool enabled)
{
if (!enabled) return;
Expand Down
1 change: 1 addition & 0 deletions src/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QColor>
#include <qwt_symbol.h>
#include <qwt_plot_curve.h>
#include <qwt_scale_map.h>
#include <math.h>
#include <algorithm>

Expand Down
4 changes: 2 additions & 2 deletions src/plotcontrolpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ PlotControlPanel::PlotControlPanel(QWidget *parent) :
int rmin = -rmax-1;
Range r = {double(rmin), double(rmax)};
ui->cbRangePresets->addItem(
QString().sprintf("Signed %d bits %d to +%d", nbits, rmin, rmax),
QString("Signed %1 bits %2 to +%3").arg(nbits).arg(rmin).arg(rmax),
QVariant::fromValue(r));
}
for (int nbits = 8; nbits <= 24; nbits++) // unsigned binary formats
{
int rmax = pow(2, nbits)-1;
ui->cbRangePresets->addItem(
QString().sprintf("Unsigned %d bits %d to +%d", nbits, 0, rmax),
QString("Unsigned %1 bits %2 to +%3").arg(nbits).arg(0).arg(rmax),
QVariant::fromValue(Range{0, double(rmax)}));
}
ui->cbRangePresets->addItem("-1 to +1", QVariant::fromValue(Range{-1, +1}));
Expand Down
1 change: 1 addition & 0 deletions src/plotmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QDebug>
#include "plotmenu.h"
#include "setting_defines.h"
#include "utils.h"
Expand Down
14 changes: 7 additions & 7 deletions src/portcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ PortControl::PortControl(QSerialPort* port, QWidget* parent) :
SELECT<int>::OVERLOAD_OF(&QComboBox::activated),
this, &PortControl::onTbPortListActivated);
QObject::connect(ui->cbPortList,
SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
SELECT<const QString&>::OVERLOAD_OF(&QComboBox::textActivated),
this, &PortControl::selectListedPort);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point of using OVERLOAD_OF here as textActivated is not overloaded.

QObject::connect(&tbPortList,
SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
SELECT<const QString&>::OVERLOAD_OF(&QComboBox::textActivated),
this, &PortControl::selectListedPort);

// setup buttons
Expand All @@ -91,7 +91,7 @@ PortControl::PortControl(QSerialPort* port, QWidget* parent) :

// setup baud rate selection widget
QObject::connect(ui->cbBaudRate,
SELECT<const QString&>::OVERLOAD_OF(&QComboBox::activated),
SELECT<const QString&>::OVERLOAD_OF(&QComboBox::textActivated),
this, &PortControl::_selectBaudRate);

// setup parity selection buttons
Expand All @@ -100,7 +100,7 @@ PortControl::PortControl(QSerialPort* port, QWidget* parent) :
parityButtons.addButton(ui->rbOddParity, (int) QSerialPort::OddParity);

QObject::connect(&parityButtons,
SELECT<int>::OVERLOAD_OF(&QButtonGroup::buttonClicked),
SELECT<int>::OVERLOAD_OF(&QButtonGroup::idClicked),
this, &PortControl::selectParity);

// setup data bits selection buttons
Expand All @@ -110,15 +110,15 @@ PortControl::PortControl(QSerialPort* port, QWidget* parent) :
dataBitsButtons.addButton(ui->rb5Bits, (int) QSerialPort::Data5);

QObject::connect(&dataBitsButtons,
SELECT<int>::OVERLOAD_OF(&QButtonGroup::buttonClicked),
SELECT<int>::OVERLOAD_OF(&QButtonGroup::idClicked),
this, &PortControl::selectDataBits);

// setup stop bits selection buttons
stopBitsButtons.addButton(ui->rb1StopBit, (int) QSerialPort::OneStop);
stopBitsButtons.addButton(ui->rb2StopBit, (int) QSerialPort::TwoStop);

QObject::connect(&stopBitsButtons,
SELECT<int>::OVERLOAD_OF(&QButtonGroup::buttonClicked),
SELECT<int>::OVERLOAD_OF(&QButtonGroup::idClicked),
this, &PortControl::selectStopBits);

// setup flow control selection buttons
Expand All @@ -130,7 +130,7 @@ PortControl::PortControl(QSerialPort* port, QWidget* parent) :
(int) QSerialPort::SoftwareControl);

QObject::connect(&flowControlButtons,
SELECT<int>::OVERLOAD_OF(&QButtonGroup::buttonClicked),
SELECT<int>::OVERLOAD_OF(&QButtonGroup::idClicked),
this, &PortControl::selectFlowControl);

// initialize signal leds
Expand Down
5 changes: 3 additions & 2 deletions src/recordpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ RecordPanel::RecordPanel(Stream* stream, QWidget *parent) :
connect(&recordAction, &QAction::toggled, ui->pbBrowse, &QWidget::setDisabled);

QCompleter *completer = new QCompleter(this);
// TODO: QDirModel is deprecated, use QFileSystemModel (but it doesn't work)
completer->setModel(new QDirModel(completer));
// TODO: QDirModel is deprecated, use QFileSystemModel (but it doesn't work)
// Works for me
completer->setModel(new QFileSystemModel(completer));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work on 5.9 though. But change shouldn't include the comments in case we decide to merge this as is.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this with Qt 5.15, and it still doesn't work. What is your OS and version if I may ask?

My exact Qt version is 5.15.2.

completer->setCaseSensitivity(Qt::CaseInsensitive);
ui->leFileName->setCompleter(completer);

Expand Down
9 changes: 5 additions & 4 deletions src/scrollzoomer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <qwt_plot_layout.h>
#include <qwt_scale_engine.h>
#include <qwt_scale_widget.h>
#include <QStack>
#include <QRectF>
#include "scrollbar.h"
#include "scrollzoomer.h"

Expand Down Expand Up @@ -304,12 +306,11 @@ bool ScrollZoomer::eventFilter( QObject *object, QEvent *event )
{
case QEvent::Resize:
{
int left, top, right, bottom;
canvas()->getContentsMargins( &left, &top, &right, &bottom );

QMargins c_margins = canvas()->contentsMargins();
QRect rect;
rect.setSize( static_cast<QResizeEvent *>( event )->size() );
rect.adjust( left, top, -right, -bottom );
rect.adjust( c_margins.left(), c_margins.top(),
-c_margins.right(), -c_margins.bottom() );

layoutScrollBars( rect );
break;
Expand Down
2 changes: 1 addition & 1 deletion src/sneakylineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SneakyLineEdit::SneakyLineEdit(QWidget *parent) :
{
setFrame(false);
setStyleSheet("QLineEdit{background-color: rgba(0,0,0,0);}");
setToolTip(trUtf8("Click to edit"));
setToolTip("Click to edit");

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again why not use tr here?

setBold(true);
}
Expand Down
4 changes: 3 additions & 1 deletion src/zoomer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

#include "zoomer.h"
#include <qwt_plot.h>
#include <QPen>
#include <qwt_text.h>
#include <QPainter>
#include <QPainterPath>
#include <QMouseEvent>
#include <QtMath>
#include <algorithm>
Expand Down