Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: Qt5 and embedwidgets

  1. #1
    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 Qt5 and embedwidgets

    Hi,

    so far i worked with Qt 4.x , and i used QX11EmbedWidgets and QX11EmbedContainer classes for embedding my applications.

    now we need to convert this code to Qt5, i heard there are lot of advancements and changes done to Qt5.

    if anybody has any idea how embedding of widgets is done in Qt5, please help me.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    For X11 Qt5 means nothing but regression as the X11 paint engine is gone and only the software renderer is left - with Qt 4.8 you can decide. For an application using vector graphics the hardware acceleration of X11 is way faster, when drawing gradients it is the other way round.

    As long as you don't plan to use QML I don't see any strong reason for porting an application to Qt5.

    Concerning your question: these classes will be reintroduced with Qt 5.1.

    Uwe

  3. #3
    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 Uwe View Post
    For X11 Qt5 means nothing but regression as the X11 paint engine is gone and only the software renderer is left - with Qt 4.8 you can decide. For an application using vector graphics the hardware acceleration of X11 is way faster, when drawing gradients it is the other way round.
    i frankley dont understand what you are trying to say . I am bit new.


    Concerning your question: these classes will be reintroduced with Qt 5.1.
    So you mean to say we cannot compile / run any application involving QX11Embed* until 5.1 is released.

    is there any other alternate in Qt5 for embedding external apps into a widgets.

    Thanks,
    Pstd

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by PstdEr View Post
    i frankley dont understand what you are trying to say
    I'm saying that for a QWidget based application running on X11 better stay with Qt4.

    Uwe

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by Uwe View Post
    For X11 Qt5 means nothing but regression as the X11 paint engine is gone and only the software renderer is left
    The X11 paint device would need to be ported to XCB first, but there is nothing in the QPA that would prevent it from using it or given an option on using it.

    It is just very likely that there are not a lot of Qt users who need that and none of them needs it enough to do the port or a new XCB based implementation.

    Quote Originally Posted by PstdEr View Post
    So you mean to say we cannot compile / run any application involving QX11Embed* until 5.1 is released.
    You don't have to wait for the release, the beta is already available (has been for quite a while). And the release is expected quite soon IIRC:

    Cheers,
    _

  6. #6
    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

    Going through your reply i understood that , there is a way to use embedwidgets in Qt 5/beta.

    I have gone through most of the examples , and found nothing about embed widgets.
    will you please provide some links for examples on Qt 5 which use embeding widgets.
    i try to compile the code with Qt 5.0 with QX11Embed* and it says cannot find such symbols.


    Thanks,

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by PstdEr View Post
    i try to compile the code with Qt 5.0 with QX11Embed* and it says cannot find such symbols.
    Is that 0 a typo? As Uwe said those classes are coming with Qt5.1, so the 5.1 beta should have them as well.

    But maybe they got postponed to 5.2?

    Cheers,
    _

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by anda_skoa View Post
    The X11 paint device would need to be ported to XCB first, but there is nothing in the QPA that would prevent it from using it or given an option on using it.
    It is just very likely that there are not a lot of Qt users who need that and none of them needs it enough to do the port or a new XCB based implementation.
    Well everyone doing remote/X11 with a certain performance needs it - but as it seems to be neglected that this use case exists nowadays ...

    Uwe

  9. #9
    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 anda_skoa View Post
    Is that 0 a typo? As Uwe said those classes are coming with Qt5.1, so the 5.1 beta should have them as well.

    But maybe they got postponed to 5.2?

    Cheers,
    _
    no , its not a typo, i am currently using Qt 5.0, i thought embedding widgets is available in Qt 5.0.

    I found below link:
    http://blog.qt.digia.com/blog/2013/0...ndowcontainer/
    i think this is what i require for achieving emebed functionality but it clearly says it is available in Qt 5.1.

    i think i will come back with some code for help..

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    This blog is about how to use Qt widgets and QML stuff together - what has absolutely nothing to do with embedding native X11 code into a Qt widget based application.

    Are you sure that you know what you want to do ?

    Uwe

  11. The following user says thank you to Uwe for this useful post:

    PstdEr (12th June 2013)

  12. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by PstdEr View Post
    no , its not a typo, i am currently using Qt 5.0, i thought embedding widgets is available in Qt 5.0.
    What in "...these classes will be reintroduced with Qt 5.1" made you reach that conclusion?


    Quote Originally Posted by PstdEr View Post
    As Uwe pointed out that is to integrate QWidgets into an application that is just using QtGui, e.g. one that is using QtQuick2 or a different UI system.

    Cheers,
    _

  13. The following user says thank you to anda_skoa for this useful post:

    PstdEr (12th June 2013)

  14. #12
    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

    what i have previously was , an application developed using QX11EmbedWidget which accepts a window id argument and opens the application in the specified window id.

    so i run the stand alone application usnig ./App 2

    where 2 is the winId ( inface we can give any number)

    the same appilcation can also be launched into someother application window which is QX11EmbedContainer widget.

    what i am expecting from the blog is

    createWindowContainer is the replacement for QX11EmbedContainer
    and
    fromWinId used to embed another window( which is an app in my case)

    (QWindow * QWindow::fromWinId(WId id) [static]) (http://doc-snapshot.qt-project.org/5...equestActivate)

    is my understanding correct. i have not tried these in a program yet and there are no sample snippets .

  15. #13
    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

    here is my sample app using Qt 4.8 , i need to find the Qt5 equivalent calls to make it work.

    sorry i could not attach zip or tar ..

    container related files

    applicationwindow.cpp
    ------------------------------

    Qt Code:
    1. #include "applicationwindow.h"
    2.  
    3. ApplicationWindow::ApplicationWindow(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6.  
    7. }
    8. ApplicationWindow::ApplicationWindow(int min_width,int min_height,int max_width,int max_height,QWidget* parent)
    9. :min_width(min_width),min_height(min_height),max_width(max_width),max_height(max_height),QWidget(parent)
    10. {
    11.  
    12. }
    13.  
    14. ApplicationWindow::~ApplicationWindow()
    15. {
    16. /*
    17.   if (window != NULL)
    18.   {
    19.   delete window;
    20.   window = NULL;
    21.   }*/
    22. }
    23.  
    24. QX11EmbedContainer* ApplicationWindow::createApplicationWindow()
    25. {
    26. window = new QX11EmbedContainer();
    27. window->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    28. // display->showFullScreen();
    29. pl.setColor(QPalette::Window,Qt::black);
    30. window->setAttribute(Qt::WA_PaintOnScreen,true);
    31. window->setPalette(pl);
    32. // display->setGeometry(0,0,700,256);
    33. window->setMouseTracking(true);
    34. window->setMinimumSize(min_width,min_height);
    35. window->setMaximumSize(max_width,max_height);
    36. return window;
    37. }
    To copy to clipboard, switch view to plain text mode 


    applicationwindow.h
    -------------------------------

    Qt Code:
    1. #ifndef APPLICATIONWINDOW_H
    2. #define APPLICATIONWINDOW_H
    3.  
    4. #include <QWidget>
    5. #include <QX11EmbedContainer>
    6.  
    7.  
    8. class ApplicationWindow : public QWidget
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit ApplicationWindow(QWidget *parent = 0);
    13. explicit ApplicationWindow(int min_width,int min_height,int max_width,int max_height,QWidget* parent=0);
    14. QX11EmbedContainer* createApplicationWindow();
    15.  
    16.  
    17. public:
    18. virtual ~ApplicationWindow();
    19. private:
    20. int max_width;
    21. int max_height;
    22. int min_width;
    23. int min_height;
    24.  
    25. signals:
    26.  
    27. public slots:
    28.  
    29. };
    30.  
    31. #endif // APPLICATIONWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    main.cpp
    -----------

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow *Container;
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. QApplication qapp(argc, argv);
    8. Container = new MainWindow();
    9.  
    10. Container->show();
    11. return qapp.exec();
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 



    mainwindow.cpp
    -------------------------
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #define HEIGHT 708
    4. #define FTP_HEIGHT 60
    5. #define WIDTH 196
    6.  
    7. #define HELLOTEST "../hellotest/hellotest"
    8.  
    9. extern MainWindow *Container;
    10.  
    11. MainWindow::MainWindow(QWidget *parent)
    12. : QMainWindow(parent)
    13. {
    14.  
    15. ApplicationProcess = NULL;
    16. QWidget* mainwindow = new QWidget();
    17.  
    18. getDisplayProperties(&max_width,&max_height);
    19. setWindowMinimumSizes(max_width - 300,HEIGHT - 100);
    20. setWindowMaximumSizes(max_width,max_height);
    21.  
    22. createActions();
    23. createMenus();
    24.  
    25. mainwindow->setMinimumSize(min_width,min_height);
    26. mainwindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    27. mainwindow->setMaximumSize(max_width,max_height);
    28. setCentralWidget(mainwindow);
    29.  
    30. QPalette pl ;
    31. pl.setColor(pl.Background,Qt::white);
    32.  
    33. mainwindow->setAutoFillBackground(true);
    34. mainwindow->setPalette(pl);
    35.  
    36. vLayout = new QVBoxLayout();
    37. mainLayout = new QHBoxLayout();
    38. vWidget = new QWidget();
    39.  
    40. appwindow = new ApplicationWindow (min_width - WIDTH ,min_height - (FTP_HEIGHT + 105),max_width - WIDTH,max_height - (100 +FTP_HEIGHT ) );
    41. display = appwindow->createApplicationWindow();
    42.  
    43. vWidget->setLayout(vLayout);
    44.  
    45. vLayout->addWidget(display);
    46. vLayout->setSpacing(1);
    47.  
    48. mainLayout ->addWidget(vWidget);
    49. mainwindow ->setLayout(mainLayout);
    50. vLayout->setContentsMargins(0,0,0,0);
    51. display->setContentsMargins(0,0,0,0);
    52. mainwindow->setContentsMargins(0,0,0,0);
    53.  
    54. mainwindow->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    55. display->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    56.  
    57. }
    58.  
    59. void MainWindow::getDisplayProperties(int* width,int* height )
    60. {
    61. int x = 0,y = 0;
    62. QRect rec;
    63. rec = D.geometry();
    64. rec.getRect(&x,&y,width,height);
    65. }
    66.  
    67. void MainWindow::setWindowMinimumSizes(int min_width,int min_height)
    68. {
    69.  
    70. this->min_width = min_width;
    71. this->min_height = min_height;
    72.  
    73. printf("Minimum Height is %d\n",min_height);
    74.  
    75. }
    76. void MainWindow::setWindowMaximumSizes(int max_width,int max_height)
    77. {
    78. this->max_width = max_width;
    79. this->max_height = max_height;
    80. }
    81.  
    82. void MainWindow::createActions()
    83. {
    84. HelloTestAct = new QAction(tr("&HelloTest"),this);
    85. connect(HelloTestAct,SIGNAL(triggered()),this,SLOT(Launch_Hello_Test()));
    86.  
    87. }
    88.  
    89. void MainWindow::Launch_Hello_Test()
    90. {
    91.  
    92. qDebug() << "Launch_Hello_Test";
    93.  
    94. ApplicationProcess = new QProcess(display);
    95. QString executable(HELLOTEST);
    96. QStringList arguments;
    97. arguments << QString::number(display->winId());
    98. ApplicationProcess->start(executable, arguments);
    99. }
    100.  
    101. void MainWindow::createMenus()
    102. {
    103. fileMenu = menuBar()->addMenu(tr("&File"));
    104. fileMenu->addAction(HelloTestAct);
    105. }
    106.  
    107. MainWindow :: ~MainWindow()
    108. {
    109. }
    To copy to clipboard, switch view to plain text mode 


    mainwindow.h
    ----------------------

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QDialog>
    6. #include <QtGui>
    7. #include <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.  
    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.  
    31.  
    32. QWidget* mainwindow;
    33.  
    34. ApplicationWindow* appwindow;
    35. QHBoxLayout* mainLayout;
    36. QVBoxLayout* vLayout;
    37. QWidget* vWidget;
    38.  
    39. QAction* HelloTestAct;
    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. };
    51.  
    52. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    the sample test app
    this can be run by typing ./hellotest 2

    hellotest.cpp
    -------------------
    Qt Code:
    1. #include "hellotest.h"
    2.  
    3. HelloTest :: HelloTest(QWidget *parent):
    4. QWidget(parent)
    5. {
    6.  
    7. qDebug() << "in hello test";
    8. QWidget *window = new QWidget(parent);
    9. window -> resize(500,500);
    10. window -> setPalette(QPalette(QColor(0,255,0,255)));
    11. window -> setAutoFillBackground(true);
    12. this -> setLayout(vl);
    13. vl -> addWidget(window);
    14. }
    15.  
    16. HelloTest::~HelloTest()
    17. {
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 


    hellotest.h
    ------------------

    Qt Code:
    1. #ifndef HELLOTEST_H
    2. #define HELLOTEST_H
    3.  
    4. #include <QWidget>
    5. #include <QDebug>
    6. #include <QX11EmbedWidget>
    7. #include <QApplication>
    8. #include <QVBoxLayout>
    9. #include <QDebug>
    10.  
    11. class HelloTest :public QWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. HelloTest(QWidget *parent = 0);
    17. ~HelloTest();
    18. private:
    19.  
    20.  
    21.  
    22. };
    23.  
    24. #endif // HELLOTEST_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    --------------

    Qt Code:
    1. #include "hellotest.h"
    2.  
    3.  
    4. HelloTest *hellotest;
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication qapp(argc, argv);
    9. QString windowId(qapp.arguments()[1]);
    10. QVBoxLayout* layout = new QVBoxLayout;
    11.  
    12. embed = new QX11EmbedWidget;
    13. embed -> setMinimumSize(500,500);
    14. embed -> setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    15.  
    16. embed -> setPalette(QColor(255,0,0,255));
    17. embed -> setAutoFillBackground(true);
    18.  
    19. hellotest = new HelloTest(embed);
    20. hellotest -> setContentsMargins(0,0,0,0);
    21.  
    22. if(NULL == embed)
    23. {
    24. qDebug() << "Unable to create hellotest";
    25. return 0;
    26. }
    27. if(argc < 2)
    28. {
    29. qDebug() << "More Arguments Needed";
    30. return 0;
    31. }
    32. qDebug()<<"windowId in WG:"<<windowId;
    33.  
    34. layout -> addWidget(hellotest);
    35. embed -> setLayout(layout);
    36. embed -> embedInto(windowId.toULong());
    37. embed -> show();
    38. return qapp.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 

  16. #14
    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

    I am trying to embed an application in another application widget using QWindow and createWidowContainer in Qt5.

    The problem is that the window is not embedding into the application window.

    and also when i launch the applications individually i can get logs from both apps, but when i launch from container application the embedding application logs are not displayed.

    please have a look and guide me in proper direction.

    The container code:

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QProcess>
    6. #include <QDebug>
    7. #include <QtGui>
    8. #include<QHBoxLayout>
    9. #include <QtWidgets>
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20.  
    21. QWidget* display;
    22. QAction* HelloTestAct;
    23. QProcess* ApplicationProcess;
    24. QHBoxLayout* mainLayout;
    25. QMenu *fileMenu;
    26.  
    27.  
    28. void createActions();
    29. void createMenus();
    30.  
    31. private slots:
    32. void Launch_Hello_Test();
    33. void finish(int,QProcess::ExitStatus);
    34. };
    35.  
    36. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #define HELLOTEST "/home/Documents/5.1example/rasterwindow/rasterwindow"
    4.  
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent)
    7. {
    8. qDebug()<<"MainWindow";
    9. ApplicationProcess = NULL;
    10. QWidget* mainwindow = new QWidget();
    11. mainLayout = new QHBoxLayout();
    12. mainwindow->setMinimumSize(500,500);
    13. createActions();
    14. createMenus();
    15. setCentralWidget(mainwindow);
    16.  
    17. QPalette pl ;
    18. pl.setColor(pl.Background,Qt::white);
    19.  
    20. mainwindow->setAutoFillBackground(true);
    21. mainwindow->setPalette(pl);
    22. mainwindow ->setLayout(mainLayout);
    23. display= createWindowContainer(0,0,0);
    24. display= createWindowContainer(0,0,0);
    25. pl.setColor(QPalette::Window,Qt::black);
    26. display->setAttribute(Qt::WA_PaintOnScreen,true);
    27. display->setPalette(pl);
    28. }
    29.  
    30. void MainWindow::createActions()
    31. {
    32. HelloTestAct = new QAction(tr("&HelloTest"),this);
    33. connect(HelloTestAct,SIGNAL(triggered()),this,SLOT(Launch_Hello_Test()));
    34.  
    35. }
    36.  
    37. void MainWindow::Launch_Hello_Test()
    38. {
    39.  
    40. qDebug() << "Launch_Hello_Test";
    41.  
    42. ApplicationProcess = new QProcess(display);
    43. QString executable(HELLOTEST);
    44. QStringList arguments;
    45. arguments << QString::number(display->winId());
    46. qDebug() << "window id" << arguments.at(0);
    47. connect(ApplicationProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(finish(int,QProcess::ExitStatus)));
    48. ApplicationProcess->start(executable, arguments);
    49. }
    50.  
    51. void MainWindow::finish(int,QProcess::ExitStatus)
    52. {
    53. qDebug()<<"finish";
    54. }
    55.  
    56. void MainWindow::createMenus()
    57. {
    58. fileMenu = menuBar()->addMenu(tr("&File"));
    59. fileMenu->addAction(HelloTestAct);
    60. }
    61.  
    62. MainWindow :: ~MainWindow()
    63. {
    64. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QApplication>
    3.  
    4. MainWindow *Container;
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication qapp(argc, argv);
    8. qDebug()<<"in Main";
    9. Container = new MainWindow();
    10. Container->show();
    11. return qapp.exec();
    12.  
    13. #if 0
    14. QApplication a(argc, argv);
    15. MainWindow w;
    16. w.show();
    17. return a.exec();
    18. #endif
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    The Embedding application:I am trying to embed an application from Qt Example itself
    from Rasterwindow in Qt Examples

    rasterwindow.h
    Qt Code:
    1. #ifndef RASTERWINDOW_H
    2. #define RASTERWINDOW_H
    3. #include <QtGui>
    4. class RasterWindow : public QWindow
    5. {
    6. Q_OBJECT
    7. public:
    8. explicit RasterWindow(QWindow *parent = 0);
    9. virtual void render(QPainter *painter);
    10. public slots:
    11. void renderLater();
    12. void renderNow();
    13. protected:
    14. bool event(QEvent *event);
    15. void resizeEvent(QResizeEvent *event);
    16. void exposeEvent(QExposeEvent *event);
    17.  
    18. private:
    19. QBackingStore *m_backingStore;
    20. bool m_update_pending;
    21. };
    22.  
    23. #endif // RASTERWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "rasterwindow.h"
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QGuiApplication app(argc, argv);
    6. QString windowId(app.arguments()[2]);
    7. qDebug()<<"in main form raster "<< app.arguments()[0];
    8. qDebug()<<"in main form raster "<< app.arguments()[1];
    9. qDebug()<<"in main form raster "<< app.arguments()[2];
    10.  
    11. RasterWindow window;
    12. window.fromWinId(windowId.toULong());
    13.  
    14. window.show();
    15.  
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    rasterwindow.cpp

    Qt Code:
    1. #include "rasterwindow.h"
    2.  
    3. RasterWindow::RasterWindow(QWindow *parent)
    4. : QWindow(parent)
    5. , m_update_pending(false)
    6. {
    7. m_backingStore = new QBackingStore(this);
    8. create();
    9.  
    10. setGeometry(100, 100, 300, 200);
    11.  
    12. }
    13.  
    14. bool RasterWindow::event(QEvent *event)
    15. {
    16. if (event->type() == QEvent::UpdateRequest) {
    17. m_update_pending = false;
    18. renderNow();
    19. return true;
    20. }
    21. return QWindow::event(event);
    22. }
    23.  
    24. void RasterWindow::renderLater()
    25. {
    26. if (!m_update_pending) {
    27. m_update_pending = true;
    28. QCoreApplication::postEvent(this, new QEvent(QEvent::UpdateRequest));
    29. }
    30. }
    31.  
    32.  
    33. void RasterWindow::resizeEvent(QResizeEvent *resizeEvent)
    34. {
    35. m_backingStore->resize(resizeEvent->size());
    36. if (isExposed())
    37. renderNow();
    38. }
    39.  
    40. void RasterWindow::exposeEvent(QExposeEvent *)
    41. {
    42. if (isExposed()) {
    43. renderNow();
    44. }
    45. }
    46.  
    47. void RasterWindow::renderNow()
    48. {
    49. if (!isExposed())
    50. return;
    51.  
    52. QRect rect(0, 0, width(), height());
    53. m_backingStore->beginPaint(rect);
    54.  
    55. QPaintDevice *device = m_backingStore->paintDevice();
    56. QPainter painter(device);
    57.  
    58. painter.fillRect(0, 0, width(), height(), Qt::white);
    59. render(&painter);
    60.  
    61. m_backingStore->endPaint();
    62. m_backingStore->flush(rect);
    63. }
    64.  
    65. void RasterWindow::render(QPainter *painter)
    66. {
    67. painter->drawText(QRectF(0, 0, width(), height()), Qt::AlignCenter, QStringLiteral("QWindow"));
    68. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Qt5 and embedwidgets

    Quote Originally Posted by PstdEr View Post
    what i am expecting from the blog is

    createWindowContainer is the replacement for QX11EmbedContainer
    No, it is not.
    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.


  18. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    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,
    _

  19. #17
    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.

  20. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    Using a low level thread and having it emit a signal is most likely the problem because the slot will likely be called in the secondary thread's context and not in the one handling the UI.

    My recommendation is to try something simpler first, e.g. letting the rasterwindow program write its winId to stdout (followed by newline and maybe flush), which you then read in the main application through QProcess (see signal readyReadStandardOutput())

    That way you can test the child process manually, e.g. start it in a shell window and see if it correctly outputs its window id.

    i'd also recommend that you put some empty placeholder widget into the central widget and when you got the winId and have create the window container, you put the window container into a layout in that placeholder.
    You obviously need to keep a pointer to that placerholder as a member of the main window instance so you can access it from the slot connected to readyReadStandardOutput()

    Cheers,
    _

  21. #19
    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

    Thanks anda_skoa,
    i will try what you said,but before that i would like let you know the output i am getting with current program.

    When i run the raster example alone i am getting the window id printed in Qt Creator Log.
    and also if i run container first and raster second seperately i am able to receive the winid in the container but the window is not embedded into it.

    logs when running rasterwindow
    In RasterWindow
    before mq_open
    window id is : 121634822
    window id int : 121634822
    mq_open success
    window id sent is 121634822

    logs when running container

    in Main
    MainWindow
    thread create success
    Init unable to unlink
    mq_open success
    window id received is : 121634822
    unlink success
    In launch_app

    some times i am getting below errors:

    QXcbConnection: XCB error: 8 (BadMatch), sequence: 1131, resource id: 121634822, major code: 1 (CreateWindow), minor code: 0
    QXcbConnection: XCB error: 3 (BadWindow), sequence: 1134, resource id: 109051937, major code: 18 (ChangeProperty), minor code: 0

  22. #20
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 and embedwidgets

    It might be helpful to see the actual code of launch_app()
    the one you posted will obviously never embed the window since the widget is never added to any layout.

    Cheers,
    _

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.