This guide walks you through creating a basic Qt GUI application that integrates QCefView. The complete source code for this example is available in the QCefViewTest directory.
Initializing the QCefContext Instance
The first step in using QCefView is to initialize a QCefContext
instance. Think of this as the QCefView equivalent of QApplication
: you should have only one instance of QCefContext
throughout your application's lifecycle.
#include <QApplication>
#include "MainWindow.h"
int
main(int argc, char* argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Represents the CEF setting. For more details please refer to: https://bitbucket.org/chromiumembedded/...
Definition QCefConfig.h:28
void setBridgeObjectName(const QString &name)
Sets the bridge object name.
void addCommandLineSwitchWithValue(const QString &smitch, const QString &v)
Adds a switch with value to the command line args used to initialize the CEF.
void setLogLevel(const LogLevel lvl)
Sets the log level.
void addCommandLineSwitch(const QString &smitch)
Adds a switch to the commandline args used to initialize the CEF.
void setBackgroundColor(const QColor &color)
Sets the background color of the web page.
void setUserAgent(const QString &agent)
Sets the user agent.
void setRemoteDebuggingPort(short port)
Sets the remote debugging port.
@ LOGSEVERITY_DEFAULT
Default logging (currently INFO logging)
Definition QCefConfig.h:39
void setWindowlessRenderingEnabled(const bool enabled)
Sets the flag to enable/disable OSR mode.
Represents the CEF context.
Definition QCefContext.h:27
Create QCefView Instance
Once you have initialized QCefContext
, you can create a QCefView
instance.
cefViewWidget =
new QCefView(uri, &setting,
this);
ui.cefContainer->layout()->addWidget(cefViewWidget);
layout->addWidget(ui.cefContainer);
Represents the settings for individual browser.
Definition QCefSetting.h:27
void setBackgroundColor(const QColor &value)
Sets the background color.
Represents the CEF browser view.
Definition QCefView.h:49
Create a Simple Web Page
Create a simple web page with the following content:
<html>
<head>
</head>
<body id="main" class="noselect">
<h1 align="center" style="font-size: 12pt">Web Area</h1>
</body>
</html>
Run the Application
Now let's run the application.
First Project