Results 1 to 6 of 6

Thread: The Widget is not displayed when I Build and run the QT

  1. #1
    Join Date
    Dec 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default The Widget is not displayed when I Build and run the QT

    The widget window is not being displayed .
    It says like this when I build and run.
    Please help me debug the error.

    Starting /home/karthik/modbusarm2-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/modbusarm2...
    The program has unexpectedly finished.
    /home/karthik/modbusarm2-build-desktop-Desktop_Qt_4_7_4_for_GCC__Qt_SDK__Release/modbusarm2 exited with code 0
    My Qt Program is like this:-

    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "modbusarm2.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. modbusarm2 w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    modbusarm2.cpp
    Qt Code:
    1. #include "modbusarm2.h"
    2. #include "ui_modbusarm2.h"
    3. #include<QWidget>
    4. #include<QProcess>
    5.  
    6. modbusarm2::modbusarm2(QWidget *parent) :
    7. QWidget(parent),
    8. ui(new Ui::modbusarm2)
    9. {
    10. ui->setupUi(this);
    11. proc1arm1=new QProcess();
    12. QString stringproc1arm1="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adcbuttonservermainsh";
    13. QString stringproc2arm1="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adcbuttons1disp";
    14. QString stringproc3arm1="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adcbuttons2disp";
    15. QString stringproc1arm2="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adcbuttonservermain2sh";
    16. QString stringproc2arm2="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adc1buttons1disp";
    17. QString stringproc3arm2="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adc1buttons2disp";
    18.  
    19. /*Friendly Arm 1*/
    20. proc1arm1->start(stringproc1arm1);//main process of arm1
    21. connect(proc1arm1,SIGNAL(readyReadStandardOutput()),this,SLOT(arm1process()));
    22.  
    23. proc2arm1->start(stringproc2arm1);//adc value of arm1
    24. connect(proc2arm1,SIGNAL(readyReadStandardOutput()),this,SLOT(arm1adc()));
    25.  
    26. proc3arm1->start(stringproc3arm1);//buttons value of arm1
    27. connect(proc3arm1,SIGNAL(readyReadStandardOutput()),this,SLOT(arm1buttons()));
    28.  
    29. /*Friendly Arm 2*/
    30. proc1arm2->start(stringproc1arm2);//main process of arm2
    31. connect(proc1arm2,SIGNAL(readyReadStandardOutput()),this,SLOT(arm2process()));
    32.  
    33. proc2arm2->start(stringproc2arm2);//adc value of arm2
    34. connect(proc2arm2,SIGNAL(readyReadStandardOutput()),this,SLOT(arm2adc()));
    35.  
    36. proc3arm2->start(stringproc3arm2);//buttons value of arm2
    37. connect(proc3arm2,SIGNAL(readyReadStandardOutput()),this,SLOT(arm2buttons()));
    38.  
    39. /* Closing All Processess */
    40. connect(ui->close,SIGNAL(clicked()),proc1arm1,SLOT(kill()));
    41. connect(ui->close,SIGNAL(clicked()),proc2arm1,SLOT(kill()));
    42. connect(ui->close,SIGNAL(clicked()),proc3arm1,SLOT(kill()));
    43. connect(ui->close,SIGNAL(clicked()),proc1arm2,SLOT(kill()));
    44. connect(ui->close,SIGNAL(clicked()),proc2arm2,SLOT(kill()));
    45. connect(ui->close,SIGNAL(clicked()),proc3arm2,SLOT(kill()));
    46.  
    47. }
    48.  
    49. //////////////Friendly Arm 1 Functions////////////////
    50.  
    51. void modbusarm2::arm1process()
    52. {
    53. /*QString stringproc2arm1="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adcbuttons1disp";
    54.   QString stringproc3arm1="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adcbuttons2disp";
    55.   proc2arm1->start(stringproc2arm1);//adc value of arm1
    56.   connect(proc2arm1,SIGNAL(readyReadStandardOutput()),this,SLOT(modbusarm2::arm1adc()));
    57.  
    58.   proc3arm1->start(stringproc3arm1);//buttons value of arm1
    59.   connect(proc3arm1,SIGNAL(readyReadStandardOutput()),this,SLOT(modbusarm2::arm1buttons()));
    60.   */
    61. QByteArray datamain1 = proc1arm1->readAllStandardOutput();
    62. QString textmain1=ui->arm_1b_2->text()+ QString(datamain1);
    63. ui->arm_1b_2->setText(textmain1);
    64.  
    65. }
    66.  
    67. void modbusarm2::arm1adc()
    68. {
    69. QByteArray data1 = proc2arm1->readAllStandardOutput();
    70. QString text1=ui->arm_1a->text()+ QString(data1);
    71. ui->arm_1a->setText(text1);
    72.  
    73. }
    74.  
    75. void modbusarm2::arm1buttons()
    76. {
    77. QByteArray data2 = proc3arm1->readAllStandardOutput();
    78. QString text2=ui->arm_1b->text()+ QString(data2);
    79. ui->arm_1b->setText(text2);
    80.  
    81. }
    82.  
    83. //////////////Friendly Arm 2 Functions////////////////
    84.  
    85. void modbusarm2::arm2process()
    86. {
    87. /*QString stringproc2arm2="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adc1buttons1disp";
    88.   QString stringproc3arm2="/home/karthik/Project2ndyearfinal/modbus_multiple_devices/adcbuttonsmain/adc1buttons2disp";
    89.   proc2arm2->start(stringproc2arm2);//adc value of arm2
    90.   connect(proc2arm2,SIGNAL(readyReadStandardOutput()),this,SLOT(modbusarm2::arm2adc()));
    91.  
    92.   proc3arm2->start(stringproc3arm2);//buttons value of arm2
    93.   connect(proc3arm2,SIGNAL(readyReadStandardOutput()),this,SLOT(modbusarm2::arm2buttons()));
    94.   */
    95. QByteArray datamain2 = proc1arm2->readAllStandardOutput();
    96. QString textmain2=ui->arm_2b_2->text()+ QString(datamain2);
    97. ui->arm_2b_2->setText(textmain2);
    98.  
    99. }
    100.  
    101. void modbusarm2::arm2adc()
    102. {
    103. QByteArray data3 = proc2arm2->readAllStandardOutput();
    104. QString text3=ui->arm_2a->text()+ QString(data3);
    105. ui->arm_2a->setText(text3);
    106.  
    107. }
    108.  
    109. void modbusarm2::arm2buttons()
    110. {
    111. QByteArray data4 = proc3arm2->readAllStandardOutput();
    112. QString text4=ui->arm_2b->text()+ QString(data4);
    113. ui->arm_2b->setText(text4);
    114.  
    115. }
    116.  
    117. ////////Ending Functions///////////////
    118.  
    119. modbusarm2::~modbusarm2()
    120. {
    121. delete ui;
    122. }
    To copy to clipboard, switch view to plain text mode 


    modbusarm2.h


    Qt Code:
    1. #ifndef MODBUSARM2_H
    2. #define MODBUSARM2_H
    3. #include <QProcess>
    4. #include <QWidget>
    5.  
    6. namespace Ui {
    7. class modbusarm2;
    8. }
    9.  
    10. class modbusarm2 : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. modbusarm2(QWidget *parent = 0);
    16. ~modbusarm2();
    17. QProcess* proc1arm1;
    18. QProcess* proc2arm1;
    19. QProcess* proc3arm1;
    20. QProcess* proc1arm2;
    21. QProcess* proc2arm2;
    22. QProcess* proc3arm2;
    23.  
    24. public slots:
    25. void arm1process();
    26. void arm1buttons();
    27. void arm1adc();
    28. void arm2process();
    29. void arm2buttons();
    30. void arm2adc();
    31.  
    32.  
    33. private:
    34. Ui::modbusarm2 *ui;
    35. };
    36.  
    37. #endif // MODBUSARM2_H
    To copy to clipboard, switch view to plain text mode 

    modbusarm2.pro

    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2011-12-21T14:00:49
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. TARGET = modbusarm2
    10. TEMPLATE = app
    11.  
    12.  
    13. SOURCES += main.cpp\
    14. modbusarm2.cpp
    15.  
    16. HEADERS += modbusarm2.h
    17.  
    18. FORMS += modbusarm2.ui
    To copy to clipboard, switch view to plain text mode 

    and i am including modbusarm2.ui file too please help modbusarm2.ui

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The Widget is not displayed when I Build and run the QT

    Did you even try to run a debugger?

    On line 23, 26, 30, 33 and 36 in your .cpp file you're accessing invlalid pointers so no wonder your app crashes.

    You need to repeat line 11 for every pointer defined in the header file.

  3. The following user says thank you to Spitfire for this useful post:

    karthikkm1987 (22nd December 2011)

  4. #3
    Join Date
    Dec 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: The Widget is not displayed when I Build and run the QT

    Thanks.it worked.Yes you were right i didnt create new processes initially.
    One more thing Is it possible to select required data from the readAllStandardOutput() output of QProcess and put them seperately in textedits or lineedits????
    can you give me example?

  5. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The Widget is not displayed when I Build and run the QT

    Probably it is possible, but I don't quite understand your question.

    Do you want to break the output into lines, or do you want to extract some data from a line?
    In both cases you just need to find what you're looking for in QByteArray.

    Depending on what you need it may be easier to go different route rather tahn readAllStandardOutput().

  6. #5
    Join Date
    Dec 2011
    Posts
    13
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: The Widget is not displayed when I Build and run the QT

    the shell script is like this.
    Qt Code:
    1. #!/bin/bash
    2. for((i=1,j=20;j,i;i++,j++))
    3. do
    4. echo "i=$i"
    5. echo "j=$j"
    6. done
    To copy to clipboard, switch view to plain text mode 

    the output will come like this when i execute in one single qprocess.
    i=1
    j=20
    i=2
    j=21
    ...........so on

    I have edited the display like this.

    Qt Code:
    1. #include "testprocess.h"
    2. #include "ui_testprocess.h"
    3. #include<QProcess>
    4.  
    5. testprocess::testprocess(QWidget *parent) :
    6. QWidget(parent),
    7. ui(new Ui::testprocess)
    8. {
    9. ui->setupUi(this);
    10. proc=new QProcess();
    11. QString stringproc="/home/karthik/test";
    12. proc->start(stringproc);
    13. connect(proc,SIGNAL(readyReadStandardOutput()),this,SLOT(dataread()));
    14. connect(ui->close,SIGNAL(clicked()),proc,SLOT(kill()));
    15. }
    16.  
    17. void testprocess::dataread()
    18. {
    19. QByteArray data1,data2;
    20. data1=data2=proc->readAllStandardOutput();
    21.  
    22. QString text1,text2;
    23. text1=QString(data1);
    24. text1.mid( 0, text1.indexOf(" ", 0 ) );
    25. text2=QString(data2);
    26. text2.mid( 1, text2.indexOf(" ", 1 ) );
    27. ui->ivalue->setText(text1);
    28. ui->jvalue->setText(text2);
    29. }
    30.  
    31. testprocess::~testprocess()
    32. {
    33. delete ui;
    34. }
    To copy to clipboard, switch view to plain text mode 

    here I am getting the output
    ijvalues.jpg

    What needs to be done so that
    1)I will get only output of values i=1,i=2 ..... in one text edit and j=20,j=21 ...... in another text edit.
    2)After some editing again I need to get only i and j values in separate text edits.
    Last edited by karthikkm1987; 23rd December 2011 at 07:08.

  7. #6
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: The Widget is not displayed when I Build and run the QT

    Ok, that's quite simple.

    Break the output string on new lines and then put all lines with even indexes in one dialog, and with odd indexes in other dialog.

    Qt Code:
    1. QByteArray data = proc->readAllStandardOutput();
    2. QStringList lines = QString( data ).split( "\n" );
    3. for( int i = 0; i < lines.size(); ++i )
    4. {
    5. qDebug() << i%2;
    6. if( i%2 )
    7. {
    8. ui->j_box->addLine( lines[i] );
    9. }
    10. else
    11. {
    12. ui->i_box->addLine( lines[i] );
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    That's just a mock code so don't expect it to compile, but it should give you an idea what you need to do.

    if you need to get the values only without the "i=" and "j=" before adding every line to a text box split it on "=" and take only last element. something like this:
    Qt Code:
    1. ui->j_box->addLine( lines[i].split("=").last() );
    To copy to clipboard, switch view to plain text mode 

    Note: this will probably work only when you hook it to 'finished()' signal, because when readyReadStandardOutput() is emitted not whole data is there.

    I'm not sure how readyReadStandardOutput() is emitted (if it's per line of output or less offten).
    If it's per line you need to keep track what you've read previously (i or j) and toggle between textboxes.
    If you get two lines then you can use the same approach as above.

    Hope this helps.

Similar Threads

  1. Replies: 2
    Last Post: 6th December 2010, 21:36
  2. EXC_BAD_ACCESS error when widget is displayed
    By sparticus_37 in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2010, 06:55
  3. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  4. Replies: 1
    Last Post: 20th November 2007, 18:42
  5. .png not displayed with release build
    By mnemonic_fx in forum Qt Tools
    Replies: 1
    Last Post: 5th July 2007, 09:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.