1

I am a beginner with signal & slots in QtCreator.

I would like to know how to connect a signal declared in mainwindow code in a Qwidget LCDNumber include in the mainwindow.

enter image description here

Because even if my ManWindow signal is diclared correctly (I guess)

enter image description here

I can't configure the connection between MainWindow signal and LDCNumber Display(int) SLOT it in design mode :

enter image description here

Would you know how to code the connection of MainWindow SIGNAL declared in MinWindow's Class and LCDNumber include in Mainwindow's SLOT, please?

Here are all the propeties of QLCDNumber class :

enter image description here

Thanks a lot!!

  • at first, I want to ask you never to use QT instead of Qt. QT==> QuickTime Qt==> c++ framework in QtCreator there is now no way to connect user defined signal to user defined slot. but you can connect them in c++ code by connect method. something like this : connect(widgetA, SIGNAL(signal()), widgetB, SLOT(slot()); – SajadBlog Jan 25 '21 at 05:17
  • Ok, Qt, got it. I tried a code like `connect(widgetA, SIGNAL(signal()), widgetB, SLOT(slot());` but I have no Widget A to connect only a QObject in my C++ code. I just wanna link my C++ code to the "widget B" LCDNumber widget in the MainWindow. What should I write instead of `widgetB, SLOT(slot())` please? – Nicolas Brx Jan 25 '21 at 06:32
  • I recommend that you read the official document https://doc.qt.io/qt-5/signalsandslots.html in your case you can write the below code : if QMainview object named mainView and LCDNumber named lcd connect(mainView, SIGNAL(Vxx_cost_disp_update(int)), lcd, SLOT(on_Vxx_cost_disp_update(int))); – SajadBlog Jan 25 '21 at 07:35
  • Hello Sajad, thanks for sharing the signals & slots topic. I already read it. I added the propeties of my LCD object in my post above and I tried to code the connection as you suggested : `connect(&Vxx_cost_disp,SIGNAL(TransmitConnectorValue(int)),this,SLOT(on_Vxx_cost_disp_updated(int))); connect(this, SIGNAL(Vxx_cost_disp_update(int)), &lcdNumber, SLOT(display(int)));` But it still say that "lcdNumber" is not declared in that scope. (I also tried to replace "this" by "MainWindow" as you suggested and "&ldcNumber" by "&QLCDNumber") – Nicolas Brx Jan 25 '21 at 12:35
  • @NicolasBrx , use new Signal Slot syntax, it gives better compilet time warnings: https://wiki.qt.io/New_Signal_Slot_Syntax – Roman Pavelka Jan 25 '21 at 12:38
  • Thanks Roman! I tried to decladre the connection the new may but "lcdNumber" is not recognized by connect function... `connect(Vxx_cost_disp,&MainWindowSignal::TransmitConnectorValue(int),lcdNumber,&QLCDNumber::display(int));` (I posed my QLCDNumber object properties above) – Nicolas Brx Jan 25 '21 at 12:56
  • can you share your project or a simple project that demonstrates your problem? note: when any *.ui file send to UIC(what happened in your case) ,a new file was generated that contains all new widgets that inserted in UI file and his name is like ui_classname. finally added all them to base class and declare a ui variable .you have to add "ui->" before call widget.some things like this ==> "ui->lcdnumber" – SajadBlog Jan 25 '21 at 13:51
  • https://estaca-my.sharepoint.com/:u:/g/personal/nicolas_bierinx_estaca_eu/EcMJ4ZOkTxRHi0a9xeyP_gIB2gfCO4SOV5HX7ixARW7-Cw?e=Hfu6UZ Here is a link to my OneDrive. By running the programme you should have a QDebug display each second. Then you will find the issue commented on line 46 of Mainwindow.cpp and it's description on line 43 to 45. This code is compiled on a Raspberry Pi 3B+. – Nicolas Brx Jan 26 '21 at 06:31

0 Answers0