There is a problem with the slot defined in Qt Correct

Updated on number 2024-05-27
3 answers
  1. Anonymous users2024-02-11

    Step 1: connect(spin,signal(valuechanged(int)),slider,slot(setslidervalue(int)))).

    connect(slider,signal(valuechanged(int)),spin,slot(setspinvalue(int)))

    Step 2: (Supplement the slot declaration yourself).

    void widget::setslidervalue(int nspinvalue)

    if (slider->value() = (nspinvalue+100))

    slider->setvalue(nspinvalue+100);

    void widget::setspinvalue(int nslidervalue)

    if (spin->value() = (nslidervalue-100))

    spin->setvalue(nslidervalue-100);

  2. Anonymous users2024-02-10

    You can think of the relationship between signals and slots as a matter of function calls. When a signal is sent out somewhere in your program, for example.

    emit valuechanged(100), then it is equivalent to the slot you want to call connected to this signal, that is, the previous sentence can be understood as a call.

    setnum(100)。

    Of course, signals and slots are more advanced than the above calls, e.g. the setnum(100) function can be called after the execution of a function containing emit valuechanged(100) has been completed. You can also call setnum(100) where emit valuechanged(100) is executed, and then proceed to the next sentence after setnum(100) is executed. As "ianynchen" puts it, it's equivalent to a function pointer.

    Since it is equivalent to a function call, the type and order of parameters of the signal and the slot should be the same. Of course, if the number of parameters of the signal is greater than the number of parameters associated with the slot, more of these parameters cannot be passed into the slot, so it is ignored.

    Modular programming can be facilitated by the use of signals and slot mechanisms, which means that when writing a module, you don't care who receives the signal and what it will do after receiving it, and you don't care who sends the signal and how it is sent. You can try to have one module call another module's functions without signaling and slotting, and you will find that you need to know the structure of both modules before you can proceed.

    At the same time, signals and slots can be dynamically linked and unconnected, which is very flexible.

    Signals and slots are a very important part of Qt, and it is recommended that you spend more time learning them, and the flexible use of signals and slots can greatly simplify your programming work. It is recommended that you take a good look at the section of the help documentation on signals and slots.

    The implementation of signals and slots is actually QT translating your source ** into a standard cpp source file containing MOC, and then compiling the connection. If you have time, you can compare your source** with the translated source containing MOC**.

  3. Anonymous users2024-02-09

    Both the return type of signal and slot are void, so you can think of it as requiring the number of input parameters, type, and return type to be the same. Connect accepts char*, so in fact, signal and slot convert the following parameters to char*. To put it bluntly, you can understand signal and slot as function pointers, but because they are pointers to object functions, you must first give object pointers, and then functions.

    The signal slot mechanism is actually nothing more than calling the corresponding slot function from the signal function. Therefore, the signatures of signal and slot must be consistent. Otherwise, it would be too complicated to set the corresponding way of the parameters.

    You can think of signals and slots as extended macros. The purpose of this macro is to make a markup, which can only connect signal to signal or slot, and cannot be connected to any function. In this regard, Qt is not as flexible as Boost.

Related questions
7 answers2024-05-27

The problem of notebook graphics card is difficult to repair, and the general fundamental solution is to replace the graphics card chip (if it is a desktop, replace the entire graphics card), think you should analyze the situation from two aspects:First. >>>More

10 answers2024-05-27

If the headset can't be connected, it won't be a poor microphone contact, lz in addition to going to Suo Ai after-sales maintenance, there is no other way to understand your mood, but there is no way for the machine to be bad, and you don't want to see it, I believe your parents will also understand the cause and process of the matter I can also understand the idea of lz, adults see that most of the children at home will be that annoying feeling, usually they can't get used to you using a mobile phone, they will feel that you have been holding what it looks like, lz may be afraid that they take the opportunity to go crazy, On the one hand, it is repaired no matter how bad it is, and there is also the fear of blaming them, but the machine has to be repaired, and if you don't fix it, you are sorry for yourself. So on the one hand, LZ can communicate with parents, talk to them about the machine and their own ideas, explain that it is the fault of the machine, not their own cause, and I believe they will understand you. On the other hand, you should immediately go to customer service to ask about the situation, if you really want to repair it, you should ask for the price and specific pick-up date, good luck :)

6 answers2024-05-27

No more sweet words.

Once when two people were still in love, they could always hear sweet words from each other. But it's rare to hear such sweet words now, or even at all. Daily life is full of prosaic conversations, which are very different from previous performances, giving people a strong sense of disparity. >>>More

10 answers2024-05-27

If you have problems with your iPhone, you can restore it to its original settings by clicking "Restore", which means: connect your phone to the computer, and the iTunes software on the computer will have the information you backed up for the first time. When you select the "Restore" button, you'll be able to restore your phone's original settings.

4 answers2024-05-27

When trying to open Device Manager in "System Properties" always prompts "MMC cannot open file C: Windows System32. This could be due to the file not existing, not an MMC console, or being created with a later version of MMC. >>>More