Results 1 to 20 of 26

Thread: Qt5 and embedwidgets

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #16
    Join Date
    Mar 2013
    Location
    Hyderabad,Bangalore,India
    Posts
    70
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by wysota View Post
    No, it is not.
    Will you please show me sample code on how to embed a widget in container in Qt5.

    Quote Originally Posted by anda_skoa View Post
    The current code doesn't make any sense, you are passing the window ID into the wrong direction.

    The child application needs to determine its window's ID and send it to the host application.
    The host then needs to wrap it in a QWindow using fromWinId() and then put that window into its widget tree by using createWindowContainer()

    Cheers,
    _
    thank you very much , i modified the code .


    Now the problem is
    when i run the apps separately ,my message queue is working (receive and send )
    but if i launch from the container ->File->Hellotest , the container is not able to receive the message.

    below is the only functions i modified , rest all is same as old.

    please help/suggest a way, i dont have other go i have to finish this ...

    Still the window is not embedding...

    mainwindow.cpp - container

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QWindow>
    3. #include <QObject>
    4.  
    5. #define HEIGHT 708
    6. #define FTP_HEIGHT 60
    7. #define WIDTH 196
    8. #include <pthread.h>
    9. #include <mqueue.h>
    10. #include <QtWidgets/qwidget.h>
    11. #include <qwindow.h>
    12. #include <qwindowdefs.h>
    13.  
    14. #define HELLOTEST "/home/Documents/5.1example/rasterwindow/rasterwindow"
    15.  
    16. void *wait_for_id(void * arg);
    17.  
    18. extern MainWindow *Container;
    19.  
    20. MainWindow::MainWindow(QWidget *parent)
    21. : QMainWindow(parent)
    22. {
    23. qDebug()<< "MainWindow";
    24. ApplicationProcess = NULL;
    25. QWidget* mainwindow = new QWidget();
    26.  
    27. getDisplayProperties(&max_width,&max_height);
    28. setWindowMinimumSizes(max_width - 300,HEIGHT - 100);
    29. setWindowMaximumSizes(max_width,max_height);
    30.  
    31. createActions();
    32. createMenus();
    33.  
    34. mainwindow->setMinimumSize(min_width,min_height);
    35. mainwindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    36. mainwindow->setMaximumSize(max_width,max_height);
    37. setCentralWidget(mainwindow);
    38.  
    39. QPalette pl ;
    40. pl.setColor(pl.Background,Qt::white);
    41.  
    42. mainwindow->setAutoFillBackground(true);
    43. mainwindow->setPalette(pl);
    44.  
    45. vLayout = new QVBoxLayout();
    46. mainLayout = new QHBoxLayout();
    47. vWidget = new QWidget();
    48.  
    49. appwindow = new ApplicationWindow (min_width - WIDTH ,min_height - (FTP_HEIGHT + 105),max_width - WIDTH,max_height - (100 +FTP_HEIGHT ) );
    50. display = appwindow->createApplicationWindow();
    51.  
    52. vWidget->setLayout(vLayout);
    53.  
    54. vLayout->addWidget(display);
    55. vLayout->setSpacing(1);
    56.  
    57. mainLayout ->addWidget(vWidget);
    58. mainwindow ->setLayout(mainLayout);
    59. vLayout->setContentsMargins(0,0,0,0);
    60. display->setContentsMargins(0,0,0,0);
    61.  
    62. mainwindow->setContentsMargins(0,0,0,0);
    63.  
    64. mainwindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    65. display->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    66.  
    67. pthread_t tid;
    68. if (-1 == pthread_create(&tid,NULL,wait_for_id,NULL)){
    69. perror("pthread_create");
    70. }else{
    71. qDebug()<<"thread create success";
    72. }
    73.  
    74. }
    75.  
    76. void MainWindow::getDisplayProperties(int* width,int* height )
    77. {
    78. int x = 0,y = 0;
    79. QRect rec;
    80. rec = D.geometry();
    81. rec.getRect(&x,&y,width,height);
    82. }
    83.  
    84. void MainWindow::setWindowMinimumSizes(int min_width,int min_height)
    85. {
    86.  
    87. this->min_width = min_width;
    88. this->min_height = min_height;
    89.  
    90. printf("Minimum Height is %d\n",min_height);
    91.  
    92. }
    93.  
    94. void MainWindow::setWindowMaximumSizes(int max_width,int max_height)
    95. {
    96. this->max_width = max_width;
    97. this->max_height = max_height;
    98. }
    99.  
    100.  
    101. void MainWindow::createActions()
    102. {
    103.  
    104. HelloTestAct = new QAction(tr("&HelloTest"),this);
    105. connect(HelloTestAct,SIGNAL(triggered()),this,SLOT(Launch_Hello_Test()));
    106. connect(this,SIGNAL(send_winid(int)),this,SLOT(launch_app(int)));
    107. }
    108.  
    109.  
    110. void MainWindow::Launch_Hello_Test()
    111. {
    112.  
    113. qDebug() << "Launch_Hello_Test";
    114. pthread_t tid;
    115.  
    116. ApplicationProcess = new QProcess(display);
    117. QString executable(HELLOTEST);
    118. QStringList arguments;
    119.  
    120. //connect( ApplicationProcess,SIGNAL(readyReadStandardError()),logwindow,SLOT(readStandardError()));
    121. //connect( ApplicationProcess,SIGNAL(readyReadStandardOutput()),logwindow,SLOT(readStandardOutput()));
    122.  
    123. connect(ApplicationProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(finish(int,QProcess::ExitStatus)));
    124. ApplicationProcess->start(executable, arguments);
    125.  
    126.  
    127. }
    128.  
    129. void * wait_for_id( void *arg)
    130. {
    131. struct mq_attr mqAttr;
    132. char buffer[1024];
    133. mqd_t msgid;
    134. int ret_val;
    135. int winid;
    136. mqAttr.mq_maxmsg = 10;
    137. mqAttr.mq_msgsize = 512;
    138.  
    139. if(mq_unlink("/embed6")<0)
    140. qDebug()<<"Init unable to unlink";
    141. else
    142. qDebug()<<"Init unlink success";
    143.  
    144. msgid = mq_open("/embed6",O_RDWR|O_CREAT,0777,&mqAttr);
    145.  
    146. if(-1 == msgid){
    147. perror("mq_open");
    148. return NULL;
    149. }else{
    150. qDebug()<< "mq_open success";
    151. }
    152.  
    153. ret_val = mq_receive(msgid,buffer,sizeof(buffer),NULL);
    154.  
    155. if(-1 == ret_val) {
    156. qDebug() << "mq_receive ret_val(Err) = "<< ret_val;
    157. }
    158. else {
    159. qDebug() << "window id received is :"<< buffer;
    160. mq_close(msgid);
    161. winid = atoi(buffer);
    162. Container->embed_window(winid);
    163. if(mq_unlink("/embed6")<0)
    164. qDebug()<<"unable to unlink";
    165. else
    166. qDebug()<<"unlink success";
    167. }
    168.  
    169. }
    170.  
    171. void MainWindow ::embed_window(int id)
    172. {
    173. emit send_winid(id);
    174.  
    175. }
    176.  
    177. void MainWindow::launch_app(int id)
    178. {
    179. qDebug()<<"In launch_app";
    180. WId winid = (WId) id;
    181. display->setLayout(vl);
    182. QWindow *wind = QWindow::fromWinId(winid);
    183. window = createWindowContainer(wind,display,0);
    184.  
    185. //vl->addWidget(window);
    186.  
    187. }
    188.  
    189. void MainWindow::finish(int,QProcess::ExitStatus)
    190. {
    191. qDebug()<<"finish";
    192. }
    193.  
    194. void MainWindow::createMenus()
    195. {
    196. fileMenu = menuBar()->addMenu(tr("&File"));
    197. fileMenu->addAction(HelloTestAct);
    198. }
    199.  
    200. MainWindow :: ~MainWindow()
    201. {
    202. }
    To copy to clipboard, switch view to plain text mode 


    mainwindow.h - container
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include<QtWidgets/QMainWindow>
    5. #include <QtWidgets/QDialog>
    6. #include <QtGui>
    7. #include <QtWidgets/qwidget.h>
    8. #include <QProcess>
    9. #include <QString>
    10.  
    11. #include "applicationwindow.h"
    12.  
    13. class MainWindow : public QMainWindow
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20. void embed_window(int id);
    21. private:
    22.  
    23. QProcess* ApplicationProcess;
    24. int max_width;
    25. int max_height;
    26. int min_width;
    27. int min_height;
    28.  
    29. QMenu *fileMenu;
    30. QWidget* mainwindow;
    31.  
    32. ApplicationWindow* appwindow;
    33. QHBoxLayout* mainLayout;
    34. QVBoxLayout* vLayout;
    35. QWidget* vWidget;
    36. QWidget* display;
    37. QAction* HelloTestAct;
    38. QWidget* window;
    39.  
    40. private:
    41. void createActions();
    42. void createMenus();
    43. void getDisplayProperties(int* width,int* height);
    44. void setWindowMinimumSizes(int min_width,int min_height);
    45. void setWindowMaximumSizes(int min_width,int max_width);
    46.  
    47.  
    48. private slots:
    49. void Launch_Hello_Test();
    50. void finish(int,QProcess::ExitStatus);
    51. void launch_app(int id);
    52. signals:
    53. void send_winid(int id);
    54. };
    55.  
    56. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    main.cpp - rasterwindow
    Qt Code:
    1. #include "rasterwindow.h"
    2. #include<mqueue.h>
    3. #include <stdio.h>
    4. #include<qwindow.h>
    5. #include<qwindowdefs.h>
    6. int main(int argc, char **argv)
    7. {
    8. struct mq_attr mqAttr;
    9. char buffer[512];
    10. mqd_t msgid;
    11. int ret_val;
    12. int winid_int;
    13. WId winid ;
    14. mqAttr.mq_maxmsg = 10;
    15. mqAttr.mq_msgsize = 512;
    16.  
    17. QGuiApplication app(argc, argv);
    18. RasterWindow window;
    19. qDebug()<<"before mq_open";
    20. winid = window.winId();
    21. qDebug()<<"window id is :"<< winid;
    22. winid_int = (int) winid;
    23. qDebug()<<"window id int :"<< winid;
    24. msgid = mq_open("/embed6",O_RDWR);
    25. if(-1 == msgid){
    26. perror("mq_open");
    27. return NULL;
    28. }else{
    29. qDebug()<<"mq_open success";
    30. }
    31.  
    32. sprintf(buffer,"%d",winid_int);
    33.  
    34. ret_val = mq_send(msgid,buffer,strlen(buffer)+1,1);
    35. if(-1 == ret_val)
    36. perror("mq_receive");
    37. else {
    38. qDebug () << "window id sent is"<< buffer;
    39. mq_close(msgid);
    40. }
    41. window.show();
    42. return app.exec();
    43. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by PstdEr; 17th June 2013 at 16:14.

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.