Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I run the gui application in the ssh command or php exec?
Forum Update on Monday, May 27th 2025

How can I run the gui application in the ssh command or php exec?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    QtCreator on a server?!
    "Qt Widgets Application" - is for GUI applications, you should select "Qt Console Application" if you do not want GUI.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi,

      To add to @jsulm, with ssh unless you ask for X forwarding, you won't have access to any X display.

      Note that since you don't show anything, there's no need to convert back and forth with QPixmap. QImage is enough for your need.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • lucidaL Offline
        lucidaL Offline
        lucida
        wrote on last edited by lucida
        #4

        The QT had installed in the sever. @jsulm

        @SGaist
        Qt Creator ->New Project -> Qt Console Application
        Kit Selection:Desktop Qt 5.6.0 GCC 64bit
        Then .pro file: modify QT -= gui to QT += gui
        The main.php
        #include <QCoreApplication>
        #include <QPainter>
        #include <QtGui>
        #include <QTextStream>
        int main(int argc, char *argv[])
        {
        QCoreApplication a(argc, argv);
        QTextStream cout(stdout, QIODevice::WriteOnly);
        QString str_img1="/home/testqt/test1.jpg";
        QImage img1 = QImage(str_img1);
        cout<<2<<endl;
        QPixmap pixmap1=QPixmap::fromImage( img1 );
        QPainter painter1(&pixmap1);
        QPen pen;
        QColor color;
        color.setRgb(112,112,112,255);
        pen.setColor(color);
        painter1.setPen(pen);
        painter1.drawPoint(10,20);
        QImage img2=pixmap1.toImage();
        QByteArray ba;
        QBuffer buf(&ba);
        img2.save(&buf,"JPG");
        cout<<ba.toBase64()<<endl;
        return 0;
        }

        Then run the application use Qt Creator,can only output : 2
        When I use ssh ,output : 2 segment fault
        The question are that:
        1:When I donot use QPixmap,what is the code about using QPainter,and Qpen,and Qcolor?
        2:When use QPixmap,How to solve the question?

        Thanks!

        1 Reply Last reply
        0
        • lucidaL Offline
          lucidaL Offline
          lucida
          wrote on last edited by
          #5

          When I donot use Gui,How can I use QImage and others like QPainter ,etc.
          Thanks!

          1 Reply Last reply
          0
          • Paul ColbyP Offline
            Paul ColbyP Offline
            Paul Colby
            wrote on last edited by Paul Colby
            #6

            Hi @lucida,

            2:when I use ssh login in the server,and go to the ,and go to the dir of the debug,like this:
            ...
            QXcbConnection: Could not connect to display aborted

            As @SGaist said, you'd need to use X11 Forwarding for the SSH option to work. Which SSH client are you using?

            Since your client is Windows, you're probably using PuTTY, in which case see Using PuTTY - 3.4 Using X11 forwarding in SSH.

            When diagnosing X11 forwarding, I highly recommend you install an ultra-simple GUI app (I like to use 'xclock'), and get that working first. That way you know if the problem is X11-over-ssh or your app.

            sudo rpm -ivh xclock
            xclock
            

            Usually, you'll want to install the xauth package on your CentOS server too, for X11 Forwarding to work.

            Cheers.

            1 Reply Last reply
            0
            • lucidaL Offline
              lucidaL Offline
              lucida
              wrote on last edited by lucida
              #7

              @Paul-colby
              Thanks for your replay.
              Use X11 Forwarding can only solve putty-ssh.
              Then how to solve the php exec the Qt application NOT having X11 or X-window,etc.
              Thanks!

              1 Reply Last reply
              0
              • lucidaL Offline
                lucidaL Offline
                lucida
                wrote on last edited by
                #8

                The important question is that:
                How to use QImage,QPainter,QPixmap,etc in the Core environment.
                If not,what should I do to deal with the needs of the IMG.
                Thanks!

                1 Reply Last reply
                0
                • Paul ColbyP Offline
                  Paul ColbyP Offline
                  Paul Colby
                  wrote on last edited by
                  #9

                  @lucida said:

                  Then how to solve the php exec the Qt application NOT having X11 or X-window,etc.

                  How are you using PHP?

                  Are you logging into the server and using a PHP script to execute your Qt application? If so, can you show as the PHP code?

                  Or are you trying to use PHP under a web server such as Apache? In which case you'd need Qt to be able to render HTML, which you can do manually, but I don't think QtGUI supports.

                  Please explain a little more what you mean by using "php to exec the application".

                  Thanks.

                  1 Reply Last reply
                  0
                  • lucidaL Offline
                    lucidaL Offline
                    lucida
                    wrote on last edited by
                    #10

                    @Paul-colby
                    Thanks !

                    testqt.php
                    <?php
                    exec("sudo whoami",$output);
                    print_r($output); //can output,right

                    exec("ls",$output);
                    print_r($output);//can output,right

                    $appdir="/home/qttest/build-untitled1-Desktop_Qt_5_6_0_GCC_64bit-Release/untitled1";
                    exec($appdir,$info);
                    print_r($info);//output nothing,wrong!
                    ?>
                    using Apache/nginx server by http://www.x.com/testqt.php
                    Thanks!

                    1 Reply Last reply
                    0
                    • Paul ColbyP Offline
                      Paul ColbyP Offline
                      Paul Colby
                      wrote on last edited by Paul Colby
                      #11

                      @lucida said:

                      $appdir="/home/qttest/build-untitled1-Desktop_Qt_5_6_0_GCC_64bit-Release/untitled1";
                      exec($appdir,$info);
                      print_r($info);//output nothing,wrong!

                      Ok, so executing any application (Qt-based on not) that way will only get you the stdout (and stderr with some effort) from the app. In this case, as @jsulm said, you should create a Qt Console Application, rather than a GUI application.

                      However, you also said:

                      When I donot use Gui,How can I use QImage and others like QPainter ,etc

                      What are you wanting to use QImage etc for? Taking a step back, what do you want the web page to be returning?

                      If, for example, you're wanting the web page to show a fully rendered Qt-based GUI in HTML, I don't think that's going to be possible. You'd probably be better off investigating something like GWT, though that's Java, and I'm not aware of a C++ equivalent.

                      If, on the other hand, you just what the script to render a single asset - eg a single PNG or JPEG image, then you can use Qt to create a console application, and output the generated image's byte data to stdout. Though in that case, I'd seriously consider using something like FastCGI to run your Qt app without PHP being involved.

                      Again, it depends on what you're trying to achieve by running Qt via PHP in a web server.

                      Cheers.

                      1 Reply Last reply
                      0
                      • lucidaL Offline
                        lucidaL Offline
                        lucida
                        wrote on last edited by
                        #12

                        Thank you very much!

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved