Search code examples
c++qtqmlqt5qqmlcomponent

How to run and show 4 executables in one qt qml window?


I have a 4 different executable program, you can consider that those are empty rectangle same sized windows, and i want to run those exes in one qt qml window.

enter image description here

a,b,c,d are different executables that fixed same size, and x is a windows that written in qt5.11/qml quick2, how can i do that in qt/qml project, any ideas?

I am trying with window container but no progress. The exe is writing its window id to a text and i am reading from that text.

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.addImportPath(QLatin1String("modules"));
    viewer.setOrientation(QtQuick2ApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qrc:///main.qml"));
    viewer.showExpanded();

    QProcess ps;
    ps.start("sudo ./exe 1");

    sleep(10);
    ifstream myfile;
    myfile.open("winid.txt");
    WId id ; myfile >> id;
    cout<<"WId ? "<<id<<endl;
    myfile.close();

    //WId id = (WId)FindWindow(NULL, L"PMON");
    QWindow *container = QWindow::fromWinId(id);
    container->setFlags(Qt::FramelessWindowHint);
    QWidget *program_start = QWidget::createWindowContainer(container);
    program_start->setWindowTitle("Fero");

    QVBoxLayout *manageWindows = new QVBoxLayout(program_start);
    //manageWindows->addWidget(program_start);
    //manageWindows->setGeometry(QRect(0,0,1400,800));
    program_start->setLayout(manageWindows);
    program_start->show();


    return app.exec();
}

Solution

  • After long research i could have managed to run an executable in a qt app this is how i did: if your program has a window every windows has an id and you could use that, first of all i am running my outsource executable (4 spearate process but same exe for example)and they are writing their win id to a file, after that exes write finished, my main window program reading that wids and creating qt container with that wid`s (wid has some features like x and y axis ) when qt container created everty process goes inside that qt container and now you have some sparate processes running inside one splited window. enter image description here

    int main(int argc, char *argv[]){
        QApplication app(argc, argv);
    
        QtQuick2ApplicationViewer viewer;
        viewer.addImportPath(QLatin1String("modules"));
        viewer.setOrientation(QtQuick2ApplicationViewer::ScreenOrientationAuto);
        viewer.setMainQmlFile(QLatin1String("qrc:///main.qml"));
        viewer.showExpanded();
    
        QProcess ps;
        ps.start("sudo ./exe 1");
    
        sleep(10);
        ifstream myfile;
        myfile.open("winid.txt");
        WId id ; myfile >> id;
        cout<<"WId ? "<<id<<endl;
        myfile.close();
    
        QTableWidget* grids ;
        CreateContainer createContainerOBJ;
        grids->setCellWidget(i+(i+1),j,
                createContainerOBJ.createContainer(id[i*tableCol+j]));
        
        //createConteiner is a func has two line below    
        //createContainer func content
        //QWindow *container = QWindow::fromWinId(id);
        //program_start = QWidget::createWindowContainer(container);
    
        //manageWindows->addWidget(program_start);
        //manageWindows->setGeometry(QRect(0,0,1400,800));
        program_start->setLayout(manageWindows);
        program_start->show();
    
    
        return app.exec();
    }