Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Newcomer Ignorance
Forum Updated to NodeBB v4.3 + New Features

Newcomer Ignorance

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 355 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark K R Walker
    wrote on last edited by
    #1

    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 provided

    and
    /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 provided

    These 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

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      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 );

      jeremy_kJ 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        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 );

        jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by jeremy_k
        #3

        @JoeCFD said in Newcomer Ignorance:

        LCDRange inherits QVBoxLayout which is a layout.
        QLCDNumber *lcd = new QLCDNumber( 2, this ); <==="this" is QVBoxLayout, but not a widget

        OP 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.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        JoeCFDJ 1 Reply Last reply
        3
        • jeremy_kJ jeremy_k

          @JoeCFD said in Newcomer Ignorance:

          LCDRange inherits QVBoxLayout which is a layout.
          QLCDNumber *lcd = new QLCDNumber( 2, this ); <==="this" is QVBoxLayout, but not a widget

          OP 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.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          @jeremy_k
          He made LCDRange to inherit QVBoxLayout
          LCDRange::LCDRange( int min, int max, QWidget *parent )
          : QVBoxLayout( parent )

          jeremy_kJ 1 Reply Last reply
          1
          • JoeCFDJ JoeCFD

            @jeremy_k
            He made LCDRange to inherit QVBoxLayout
            LCDRange::LCDRange( int min, int max, QWidget *parent )
            : QVBoxLayout( parent )

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            @JoeCFD said in Newcomer Ignorance:

            @jeremy_k
            He made LCDRange to inherit QVBoxLayout

            I missed the re-derived. Thanks.

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mark K R Walker
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kevin Hoang
                wrote on last edited by
                #7

                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!

                1 Reply Last reply
                3

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved