Results 1 to 5 of 5

Thread: Problem in using UI object in other class

  1. #1
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Post Problem in using UI object in other class

    Hello,

    I am trying to use generated UI class object in my own helper class to control the functionality of the UI data(buttons) depending on the data.Here is the code:

    Main.cpp

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. //QT Created Class
    5. PSX_HMI w;
    6. w.show();
    7.  
    8. //Helper class which uses UI object
    9. CPsxHMI_stateMechine stateMachine(w.getUI_Object(), w.getCANIO_DataObject());
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //CPsxHMI_stateMechine.cpp
    2. CPsxHMI_stateMechine::CPsxHMI_stateMechine(Ui::PSX_HMIClass *f_UI_Data, cPsxHMI_CANIODataBase *f_CAN_Data)
    3. :objPsx_HMI_ui(f_UI_Data),objCanIO_Data(f_CAN_Data)
    4. {
    5. //objPsx_HMI_ui = f_UI_Data;
    6. //objCanIO_Data = f_CAN_Data;
    7. objPSX_SM_Th = this;
    8.  
    9. this->start(QThread::HighPriority);
    10. }
    11.  
    12. void CPsxHMI_stateMechine::run()
    13. {
    14. while(this->isRunning())
    15. {
    16. std::cout<<"State Mechine Thread Started"<<std::endl;
    17. /* if((SystemActivation_Sys_PSC & objCanIO_Data->g_currentActiveFunc_sint32) || (SystemActivation_Sys_PP_PSC_cPSC & objCanIO_Data->g_currentActiveFunc_sint32))
    18. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/PSC_active.png)");
    19. else
    20. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/PSC_notactive.png)");
    21.  
    22. if(SystemActivation_Sys_POC & objCanIO_Data->g_currentActiveFunc_sint32)
    23. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/POC_a.png)");
    24. else
    25. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/POC_na.png)");
    26.  
    27. if(SystemActivation_Sys_SDW & objCanIO_Data->g_currentActiveFunc_sint32)
    28. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SDW_a.png)");
    29. else
    30. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SDW_na.png)");
    31.  
    32. if(SystemActivation_Sys_SVA & objCanIO_Data->g_currentActiveFunc_sint32)
    33. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SVA_a.png)");
    34. else
    35. objPsx_HMI_ui->PSC->setStyleSheet("image: url(:/debug/PICS/SVA_na.png)");*/
    36. QThread::msleep(10);
    37. }
    38.  
    39. }
    To copy to clipboard, switch view to plain text mode 
    When I am using objPsx_HMI_ui object which is UI class object I could not run my application, Some problem with runtime libraries. It opens and immediately resets.

    Could any one help me in this regard?

    Thanks in Advance!
    Last edited by wysota; 17th January 2012 at 17:20. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem in using UI object in other class

    Hello,

    Sorry for the confusion!

    What I am looking for is something like user defined signals and slots.
    I have few Qpushbuttons I need to show different stylesheets and to make them visible depending on some Data. I want to define some signals which takes this data and when the data changes i need to call some slot to do some operations.

    Please help me in this regard.

    Thanks in Advance!

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Problem in using UI object in other class


  4. #4
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem in using UI object in other class

    Hello,

    Thanks for the reply.

    I have gone through the link, I could not get solution for the problem I am looking for.

    I have a QPushButton for which there are different button images to be shown for a particular button depending on some data change.

    I mean I have different button images for same feature like ON, OFF and error. To take a decision on whether to show ON or OFF button image I am depending on some data coming from the lower layers. so, what I am trying to do is when this data changes I want to emit an signal with its value so that I can take decision on which button image to be displayed in slot.

    I am trying to do the following but it is not working.

    Qt Code:
    1. //in .h file
    2. public slots:
    3. void generate(int);
    4.  
    5. signals:
    6. void PSCvalueChanged(int);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //Connect in Constructor of child class of QMainWindow
    2. connect(ui.pushButton,SIGNAL(PSCvalueChanged(int)),this,SLOT(generate(int)));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //Helper function called by other class when data changes
    2. void MultiGlWindows::emitSignals(int newValue)
    3. {
    4. emit PSCvalueChanged(newValue);
    5. }
    6.  
    7. //Slot Defnition
    8. void MultiGlWindows::generate(int value)
    9. {
    10.  
    11.  
    12. if(value == 3)
    13. {
    14. emit PSCvalueChanged(value);
    15. ui.pushButton->setGeometry(5, 150, 140, 50);
    16. ui.pushButton->setStyleSheet("image: url(:/debug/Images/APS_notactive.png)\n");
    17. }
    18. else{
    19. ui.pushButton->setGeometry(5, 250, 140, 50);
    20. ui.pushButton->setStyleSheet("image: url(:/debug/Images/APS_active.png)\n");
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    Could you please tell me where it went wrong? or do I need to follow any alternate approach?

    Thanks in Advance!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Problem in using UI object in other class

    I think your program has already told you (in the console) QPushButton didn't have a PSCvalueChanged(int) signal. Your app is smart, you should listen to it.

    And start using layouts in your apps, please.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 8th November 2011, 23:27
  2. Replies: 4
    Last Post: 20th August 2010, 14:07
  3. Accessing a class Object by pointer in another class
    By pdoria in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 16:59
  4. Replies: 3
    Last Post: 16th May 2007, 12:07
  5. Creating object of other class in Run() method
    By santosh.kumar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2007, 16:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.