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. Newbee is wired...
Forum Updated to NodeBB v4.3 + New Features

Newbee is wired...

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 1.8k Views 1 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.
  • Flaming MoeF Offline
    Flaming MoeF Offline
    Flaming Moe
    wrote on last edited by
    #1

    Hello there,

    i have done a simple first Project with a slider and a spinbox like probably the other 99,9% of noobs.
    One time I did it writing by it by Hand and then by doing the same with the creator.
    There are two things i´m wondering.

    1.) In the Hand written code "nothing wokrs", if i set the Maximum and the Minimum of the slider and spinbox by using the setMax and setMin functions. If i do it by setRange(min, max) everything is fine.
    @void main(int argc, char** argv)
    {
    int a;
    QApplication app(argc, argv);
    QWidget* win = new QWidget;
    QVBoxLayout* layout = new QVBoxLayout(win);
    win->setWindowTitle("Signal-Slot 2 Richtungen");
    win->setGeometry(30,30,300,300);

    QSpinBox* spin = new QSpinBox();
    
    spin->setGeometry(50,50,100,100);
    spin->setValue(22);
    spin->setRange(0,100);
    layout->addWidget(spin);
    
     QSlider* slider = new QSlider(Qt::Horizontal);
     slider->setRange(0,100);
    
    
     QObject::connect(spin, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
     QObject::connect(slider, SIGNAL(valueChanged(int)), spin, SLOT(setValue(int)));
     layout->addWidget(slider);
    win->show();
    app.exec();@
    

    2.)
    I don´t understand what the creator did for me (but it works)
    2.1) i think in the end there must be similar code generated compared to the Hand written Version? When i open the form.cpp it Looks like this
    @Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
    {
    ui->setupUi(this);
    }

    Form::~Form()
    {
    delete ui;
    }@

    For example there is no "Show" member function. But the form inherits from Qwidget and the constructor is given an Argument of the type QWidget, but in the calling main.cpp there is no Argument and AFAIK, if i define an own constructor the stock one doesn´t exist anymore.
    So my question is, where does all the stuff happen what i have written in the "Handversion"?
    @void main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    Form myForm;
    myForm.show();
    app.exec();
    }@

    best regards!

    A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What do you mean by nothing works ? It's a bit vague.

      setGeometry on the QSpinBox is useless since you put it a layout, the placement and sizing will be done for you.

      Also be aware that you have a memory leak in your application since you don't delete win.

      For more information, have a look at the "Using a Designer UI File in Your Application" chapter.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Flaming MoeF Offline
        Flaming MoeF Offline
        Flaming Moe
        wrote on last edited by
        #3

        Hello,

        by "Nothing works" i ment, that the spinbox doesn´t Change it´s value when i click the arrows and that the SIGNAL-SLOT Connections doesn´t work.

        A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you check whether you had any warning on the console ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T3STYT Offline
            T3STYT Offline
            T3STY
            wrote on last edited by
            #5

            I'm not sure how the project was setup but it compiles just fine for me (except for: unused variable 'a' warning). In the project configuration (.pro file) I set
            QT += core widgets
            in main.cpp I used the next includes:
            #include <QApplication>
            #include <QWidget>
            #include <QVBoxLayout>
            #include <QSpinBox>
            #include <QSlider>
            With no changes to your main it just works for me, including the signal-slot communication.

            1 Reply Last reply
            0
            • Flaming MoeF Offline
              Flaming MoeF Offline
              Flaming Moe
              wrote on last edited by
              #6

              The reason for the warning there is an unused variable "a", is because i try how to use the widget with the slider and spinbox to manipulate a variable i can then use.

              Am i correct, that the right way is

              • click together a widget of my desire (my_Widget)

              • set up a class (my_Class) which inherits my_Widget

              • set up a Slot in my_Class for valueChanged Signal

              • set up a GetValue(); function in my_Class

              ... it´s Long way to tip a rary^^

              A lovely day for a ̶g̶̶u̶̶i̶̶n̶̶n̶̶e̶̶s̶ DUFF^^

              1 Reply Last reply
              0
              • JeroentjehomeJ Offline
                JeroentjehomeJ Offline
                Jeroentjehome
                wrote on last edited by
                #7

                Hi,
                First of all, always first set ranges, then the working values for your spinbox. That might cause a problem when the range is still 0 to 1 and you want to set it to 22, that won't work! geometries are not used when working in layouts. Only when spacers are used and there is free space left.
                If the creator did something that you want, but you do not get how, check out the constructor in the ui file that it generates! It will teach you more then we are able to share here.
                When signal/slots are not working, there are two ways of finding out if the connection was made. First is to debug and read out the returned bool from the connect function. Also when run the application output window in creator will list warnings if connections could not be made.

                Then the last post?
                What do you need to do??
                In basic I would suggest to inherit QWidget in your designed class. (or QFrame etc etc) and yes implementing a GetValue() etc is always a good way for interfaeing with your class.
                There is no need for you to overwrite the signals from the inherited class.
                Or did I misunderstand your post??

                Greetz, Jeroen

                1 Reply Last reply
                0

                • Login

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