I am using the simple browser example and trying to add the flash player from my source folder instead of using the one from my computer.
I have modified the code as per the document
in my main.cpp before creating the QApplication I do the following:
argc = 3;
argv[1] = "--ppapi-flash-path=./PepperFlashPlayer/libpepflashplayer.so";
argv[2] = "--ppapi-flash-version=26.0.0.151";
QApplication app(argc, argv);
QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
This works fine for Linux and flash loads from my source folder (I made sure of this by removing flash .so file from my linux)
BUT my problem is on mac when I do
argc = 3;
argv[1] = "--ppapi-flash-path=./PepperFlashPlayer/PepperFlashPlayer.plugin";
argv[2] = "--ppapi-flash-version=26.0.0.151";
QApplication app(argc, argv);
QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
This does not load flash at all - I use this URL to check.
I have both the .plugin and .so in the PepperFlashPlayer folder in my source folder where main.cpp and the .pro files are.
What else do I need to do?
NOTE It does not even load the default flash player located at
/Library/Internet \Plug-Ins/PepperFlashPlayer/PepperFlashPlayer.plugin
Related
Hello I am trying to set the QWebEngine URL to an index.html file that is placed in the working directory.
I am trying to use the file by setting the URL to ./index.html but it cant seem to find the file.
Here is where my files are placed
content (Work directory)
main.cpp
content.pro
index.html
How can i open index.html through the QWebEngine without using the full system path?
here is my code
#include <QApplication>
#include <QWebEngineView>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
view.setUrl(QUrl(QStringLiteral("file:///./index.html")));
view.resize(1024, 750);
view.show();
return app.exec();
}
Try moving the html file to your project build directory (you're currently keeping it inside the source directory). Then you can build your URL this way:
QUrl url = QUrl::fromLocalFile(QDir::currentPath() + "/index.html");
and set it to the view:
QWebEngineView view;
view.setUrl(url);
view.resize(1024, 750);
view.show();
From http://doc.qt.io/qt-5/qurl.html
qDebug() << QUrl("main.qml").isRelative(); // true: no scheme
qDebug() << QUrl("qml/main.qml").isRelative(); // true: no scheme
qDebug() << QUrl("file:main.qml").isRelative(); // false: has "file" scheme
qDebug() << QUrl("file:qml/main.qml").isRelative(); // false: has "file" scheme
Try: view.setUrl(QUrl(QStringLiteral("index.html")));
As p-a-o-l-o pointed out in his answer, you're likely building out-of-source, so your index.html file has to be in the folder where content.exe is created, not in the source folder.
To make this less complicated, and safer, Qt supports embedding files in the .exe via Qt Resource files (.qrc). These can easily be created in Qt Creator, and once added to the project, the embedded files are accessed via a qrc:/// prefix.
So in your sample code, after adding a .qrc file to your project and adding index.html to it, you would adjust your code like this:
view.setUrl(QUrl(QStringLiteral("qrc:///index.html")));
This has the advantage of working regardless of build type or location, and it's a lot simpler than trying to add a file copy step to your project file (or to manually copy the file each time)
I'm making a console application on OS X that interacts with specific parts of the Desktop Environment (mainly the mouse using QCursor), so I cannot use a QCoreApplication (despite how much I want to).
The application works fine, it is just that it shows up in the dock whenever I run it from the command line. I looked at several other questions online, but none fixed the problem I'm having.
I looked into QSystemTrayIcon, and I would be fine with using it IF it would get rid of the pesky window that pops up. Here is my code narrowed down to a minimum that still has the problem I addressed above.
The .pro:
TARGET = project
QT += core
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT -= gui
CONFIG += c++11
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
main.cpp:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCursor cur;
cur.setPos(0,0);
return a.exec();
}
A workaround would be doing it manually as describe here.
Luckily, if it is a cocoa application, you can hide the Dock icon yourself. To see if it is possible, right-click (Control-click) on the application icon. If "Show Package Contents" is in the menu that appears, you can hide the icon in the Dock.
If this is the case, select "Show Package Contents" and look for the "Info.plist" file inside the Contents folder. Open this file using TextEdit by right-clicking on it and choosing "Open With - Other" from the menu.
In the file, paste the following two lines just after on the 6th line:
<key>LSUIElement</key>
<string>1</string>
Save the file and close it. For the changes to take effect, you need to move the application to the desktop and them back to its original location (OS X keeps a cache of the file, so you need to trick it into checking it again).
Now when you open the application, no icon will appear in the Dock.
Source: http://www.macosxtips.co.uk/index_files/disable-the-dock-icon-for-any-application.php
I am running a Qt program on embedded linux. My program needs to be able to read some information from a text file that is located in the same folder. When I run the program everything works OK.
I now want to make my program start at startup, so I add the line
/home/my_program_name -qws &
to one of the files in the /etc/init.d folder. When I restart my machine, the program runs but it doesn't seem to be able to read the text file. It looks like that folder has not been initialized or read when the program starts.
I should mention that the /etc/init.d folder contains several files that are executed in alphabetic order and that the Qt program is the last one to be executed (i.e. at the end of the last file).
How do I make my program access the text file at startup?
In order to open a file with relative path (e.g. same directory as application), You need to make sure current directory is program's location.
You set current directory to application's directory by using following.
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(myapplication);
QApplication a(argc, argv);
QDir::setCurrent(qApp->applicationDirPath());
...
or
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(myapplication);
QApplication a(argc, argv);
QDir::setCurrent(QFileInfo(argv[0]).absoluteDir().absolutePath());
I want to display a Pixmap into a Label on Qt.
Here is the problem, the above code doesn't display the image that I want.
Please correct me if something is wrong. I have checked again and again (even it's few lines) but it didn't lead to results!!!
QLabel *label;
label= new QLabel(this);
QPixmap jet("C:/images/image.jpg");
label->setPixmap(jet);
One other problem, it seems that it works in another machine!
By default, qt builds with “-system-libjpeg”, so sudo apt-get install libjpeg if you are on linux, and to check supporting image formats, add
qDebug() << QImageReader::supportedImageFormats ();
to add plugins to your project, go to QtSDK/Desktop/Qt/4.8.1/gcc/plugins or something like this, chose the version you use, and copy "plugins" folder to root of your project(more precisely - you need only "imageformats" folder, that lays within plugins), and in your main.cpp file add line addLibraryPath (by the way, plugin's folder contain not only dlls for release, but for debugging also, they are a bit heavy, so i would remove dlls with *d.dll, for example QtCore.dll - for release, QtCored.dll - for debugging)
QApplication a(argc, argv);
MainWindow w;
a.addLibraryPath("plugins");
w.show();
I'm trying to run a simple Qt program, and when doing so, I get a console window mentioning: QWidget: Cannot create a QWidget when no GUI is being used, and the second line This application has requested the Runtime to terminate....., and the .exe file thus stops working.
My .pro file looks as follows:
#-------------------------------------------------
#
# Project created by QtCreator 2011-04-02T07:38:50
#
#-------------------------------------------------
QT += core
QT += gui
TARGET = Hello
CONFIG += console
CONFIG += qt
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
Any ideas on that?
Thanks.
The problem is not with this .pro; it is most likely in main.cpp. Qt requires you to create a QApplication before creating any QWidget subclasses (as well as certain other classes, such as QPixmap). Your main function should begin with the line:
QApplication app(argc, argv);
and will probably end with a line like:
return app.exec();
In between these calls, you should create and show your main window.
I found that you can do it with a Qt Console project, but ofcourse it will not have the functionality of a console program when you are done with my edits.
First of all you need to exchange #include <QtCoreApplication> with #include <QApplication> in your main.cpp (where you start your application)
In the main(int,char**){
exchange QCoreApplication a(argc, argv); with QApplication a(argc, argv);
and in between QApplication and return a.exec you have your widget and other gui related stuff
and in the end you use return a.exec();}
I think I found where the issue is.
Since I'm using Qt Creator, and when creating a new project, I was choosing Qt Console Application instead of Qt Gui Application.
"QWidget: Cannot create a QWidget when no GUI is being used" happens when you application isn't QApplication instance.
From Qt docs:
QApplication specializes QGuiApplication with some functionality
needed for QWidget-based applications. It handles widget specific
initialization, finalization, and provides session management.
For any GUI application using Qt, there is precisely one QApplication
object, no matter whether the application has 0, 1, 2 or more windows
at any given time. For non-QWidget based Qt applications, use
QGuiApplication instead, as it does not depend on the QtWidgets
library.
From the docs,
the QApplication class manages the GUI application's control flow and main settings whilst
the QCoreApplication class provides an event loop for console Qt applications
I had the same problem, the default QT Console App uses the QCoreApplication instead of the QApplication to run the application.
Here is what i did to make it work
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
widget.show();
return a.exec();
}
And i did not change anything in my project file
QT += core
QT += gui
TARGET = Layouts
CONFIG += gui
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp