How can I run the gui application in the ssh command or php exec?
-
QtCreator on a server?!
"Qt Widgets Application" - is for GUI applications, you should select "Qt Console Application" if you do not want GUI. -
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.
-
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!
-
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 abortedAs @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.
-
@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! -
@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.
-
@Paul-colby
Thanks !testqt.php
<?php
exec("sudo whoami",$output);
print_r($output); //can output,rightexec("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! -
@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.