Newcomer Ignorance
-
have been trying to resurrect an application written in qt3 primarily by replacing depricated classes by current ones from qt version 6.8.3.
I have been largely successful. I have been able to build much of the corrected code. However, I’ve run into problems with custom widget classes which are derived from legitimate qt classes.
For example, I have a class originally derived from “QVBox” which has apparently been depricated for some time.
I have re-derived it from “QVBoxLayout” as given below.
LCDRange::LCDRange( int min, int max, QWidget *parent )
: QVBoxLayout( parent )
{
QLCDNumber *lcd = new QLCDNumber( 2, this );
slider = new QSlider( Qt::Horizontal, this );
slider->setRange( min, max );
connect( slider, SIGNAL(valueChanged(int)),
lcd, SLOT(display(int)) );
connect( slider, SIGNAL(valueChanged(int)),
SIGNAL(valueChanged(int)) );
}int LCDRange::value() const
{
return slider->value();
}void LCDRange::setValue( int value )
{
slider->setValue( value );
}When I try to build it or to usee qmake and make I gettwo errors. These are:
.../cdrange.cpp:17: error: no matching function for call to ‘QLCDNumber::QLCDNumber(int, LCDRange*)’
../../lcdrange.cpp: In constructor ‘LCDRange::LCDRange(int, int, QWidget*)’:
../../lcdrange.cpp:17:48: error: no matching function for call to ‘QLCDNumber::QLCDNumber(int, LCDRange*)’
17 | QLCDNumber lcd = new QLCDNumber( 2, this );
/home/mark/Morse/CW_Trainer_MKRW/cwtrainer_0.1.0/lcdrange.cpp:12: In file included from ../../lcdrange.cpp:12:
In file included from ../../lcdrange.cpp:12:
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qlcdnumber.h:27:14: note: candidate: ‘QLCDNumber::QLCDNumber(uint, QWidget)’
27 | explicit QLCDNumber(uint numDigits, QWidget* parent = nullptr);
| ^~~~~~~~~~
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qlcdnumber.h:27:50: note: no known conversion for argument 2 from ‘LCDRange*’ to ‘QWidget*’
27 | explicit QLCDNumber(uint numDigits, QWidget* parent = nullptr);
| ~~~~~~~~^
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qlcdnumber.h:26:14: note: candidate: ‘QLCDNumber::QLCDNumber(QWidget*)’
26 | explicit QLCDNumber(QWidget* parent = nullptr);
| ^~~~~~~~~~
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qlcdnumber.h:26:14: note: candidate expects 1 argument, 2 providedand
/home/mark/Morse/CW_Trainer_MKRW/cwtrainer_0.1.0/lcdrange.cpp:18: error: no matching function for call to ‘QSlider::QSlider(Qt::Orientation, LCDRange*)’
../../lcdrange.cpp:18:48: error: no matching function for call to ‘QSlider::QSlider(Qt::Orientation, LCDRange*)’
18 | slider = new QSlider( Qt::Horizontal, this );
| ^
/home/mark/Morse/CW_Trainer_MKRW/cwtrainer_0.1.0/lcdrange.cpp:11: In file included from ../../lcdrange.cpp:11:
In file included from ../../lcdrange.cpp:11:
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qslider.h:36:14: note: candidate: ‘QSlider::QSlider(Qt::Orientation, QWidget*)’
36 | explicit QSlider(Qt::Orientation orientation, QWidget parent = nullptr);
| ^~~~~~~
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qslider.h:36:60: note: no known conversion for argument 2 from ‘LCDRange’ to ‘QWidget*’
36 | explicit QSlider(Qt::Orientation orientation, QWidget parent = nullptr);
| ~~~~~~~~^
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qslider.h:35:14: note: candidate: ‘QSlider::QSlider(QWidget)’
35 | explicit QSlider(QWidget *parent = nullptr);
| ^~~~~~~
/opt/Qt/6.8.3/gcc_64/include/QtWidgets/qslider.h:35:14: note: candidate expects 1 argument, 2 providedThese errors make no sense to me since the constructors for both “ qlcdnumber” and “qslider” accept two arguments and the second argument in both cases is the parent argument pointer of type Qwidget. Sinced the “this” pointer refers to an instantiation (Object) of LCDRange class which is of type Qwidget as a consequence of the inheritance from “QVBoxLayout”, the c++ code therefore seems to me to be correct.
Clearly, I’m missing something but I can’t seem to find out what I’m missing?
Would someone please point out what I’m missing.Thank you in advance.
Mark Walker -
LCDRange inherits QVBoxLayout which is a layout.
QLCDNumber *lcd = new QLCDNumber( 2, this ); <==="this" is QVBoxLayout, but not a widget.
A widget is needed for "this" in QLCDNumber( 2, this );@JoeCFD said in Newcomer Ignorance:
LCDRange inherits QVBoxLayout which is a layout.
QLCDNumber *lcd = new QLCDNumber( 2, this ); <==="this" is QVBoxLayout, but not a widgetOP wrote QVBox, not QVBoxLayout. The former is a QWidget with layout capability built in .
@Mark-K-R-Walker said in Newcomer Ignorance:
have been trying to resurrect an application written in qt3 primarily by replacing depricated classes by current ones from qt version 6.8.3.
If you haven't already seen it, Qt 4's Qt3Support may be helpful in making a Qt 3 -> 4 transition. Those classes are gone in Qt 5. The transition support for 4 -> 5 is subtler.
For 5 -> 6, there is once again a set of support classes.
Making 3 major version jumps, whether incrementally or in a single step, is likely to leave a lot of compatibility cruft. If strict compatibility isn't a requirement, it might be faster and cleaner to reimplement rather than port.
-
@JoeCFD said in Newcomer Ignorance:
LCDRange inherits QVBoxLayout which is a layout.
QLCDNumber *lcd = new QLCDNumber( 2, this ); <==="this" is QVBoxLayout, but not a widgetOP wrote QVBox, not QVBoxLayout. The former is a QWidget with layout capability built in .
@Mark-K-R-Walker said in Newcomer Ignorance:
have been trying to resurrect an application written in qt3 primarily by replacing depricated classes by current ones from qt version 6.8.3.
If you haven't already seen it, Qt 4's Qt3Support may be helpful in making a Qt 3 -> 4 transition. Those classes are gone in Qt 5. The transition support for 4 -> 5 is subtler.
For 5 -> 6, there is once again a set of support classes.
Making 3 major version jumps, whether incrementally or in a single step, is likely to leave a lot of compatibility cruft. If strict compatibility isn't a requirement, it might be faster and cleaner to reimplement rather than port.
-
@jeremy_k
He made LCDRange to inherit QVBoxLayout
LCDRange::LCDRange( int min, int max, QWidget *parent )
: QVBoxLayout( parent ) -
I am grateful for the responses.
I didn't quite understand that layout classes were not widgets.
Guess I need to do a bit more reading to understand the differences. Was trying to do this quickly without much understanding of Mt.
Moreover, the way I got the CW trainer code was not directly from SourceForge. I therefore had no idea what the GUI looked like. Reimplementation was going to be difficult.I have since visited the relevant SourceForge page. which shows a picture of the GUI. I can now reimplement it using QT Creator.
Still got to do a bit more reading though. Hi Hi.Again, many thanks.
-
In Qt3, QVBox is a widget, not a QVBoxLayout. You have two options to handle this:
- Recreate QVBox by subclassing QWidget. Inside it, use a QVBoxLayout to arrange the child items.
- Make LCDRange inherit from QWidget, add the slider into a QVBoxLayout inside it, and adjust the layout to match the original logic.
Hope this helps you!