PDA

View Full Version : Not-So-Fancy Browser doesn't open windows



ba0223
8th October 2013, 17:35
Hi,

i'm new to both c++ and Qt and started using it because I need a kind of Kioskbrowser which shall only access one web application (I programmed), in full screen mode. So I took the "Fancy Browser" from the examples and got rid of everything I didn't need. I found how to switch it in full screen mode and how to adjust some settings like enabling (Flash- & PDF viewer-)PlugIns, LocalStorage and other stuff I need. It is almost in a state I want it but than I came across a problem I haven't been able to solve:

The web application uses Javascript open() and close() methods for new windows. But my not-so-fancy browser just doesn't react and stays in its one window. After some googling I decided to ask here as there are a lot of concepts I haven't got a clue about involved, and maybe there's an easy answer. How to make it open and close new full screen windows via Javascript? And close the application should there be only one window open?

ChrisW67
8th October 2013, 21:34
QWebView::createWindow() and
QWebPage::createWindow()

ba0223
10th October 2013, 17:48
QWebView::createWindow() and
QWebPage::createWindow()


Well, thanks I guess but that doesn't really help me. I found references to this already and have the setting "JavascriptCanOpenWindows" in my little bunch of tweaks. But I have no idea where and how (and why) to reimplement createWindows. I tried to add stuff like this (http://qt-project.org/forums/viewthread/17635) in plenty variations but I don't know where to put it and how to make it work with what I already have. Here's my MainWindow - what's left from FancyBrowser and settings added by me:


MainWindow::MainWindow(const QUrl& url)
{

QNetworkProxyFactory::setUseSystemConfiguration(tr ue);

view = new QWebView(this);

view->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
view->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindow s, true);
view->settings()->setAttribute(QWebSettings::JavascriptCanCloseWindo ws, true);
view->settings()->setAttribute(QWebSettings::JavascriptCanAccessClip board, true);
view->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
view->settings()->enablePersistentStorage(QString("/data"));

view->setContextMenuPolicy(Qt::NoContextMenu);

showFullScreen();

view->load(url);

setCentralWidget(view);

}

ba0223
29th October 2013, 15:13
Hi, it's me again.

After switching to Python it was a bit easier for me to make myself familiar with the qtwebkit stuff and I managed to solve the problem described in the OP. The last hurdle to "my own browser" is to get persistent cookies to work. I managed to tap the cookies when they arrive in my own cookiejar via setCookiesFromUrl and write them into a file. As "my browser" will only visit my own page I don't have to care about anything but name and value of the cookies.

I figured that putting them back on the way to the website works via cookiesForUrl, but now I have the problem that I don't know what to do with the data I got back from my file. How to return them from the function? I have a simple string "key1=value1;key2=value2;..." in my file. No matter if I try to return it as string or array, it doesn't arrive. Does it have to have a special name, or is "return" not the way at all? Or am I at the wrong place with cookiesForUrl? Any help appreciated.

anda_skoa
30th October 2013, 11:00
Well, the C++ API returns a list of QNeworkCookie objects.
Have you tried to create and Python array of these?

Cheers,
_

ba0223
30th October 2013, 16:11
Well, the C++ API returns a list of QNeworkCookie objects.
Have you tried to create and Python array of these?

Cheers,
_


I thought in that direction and did try to create a QNetworkCookie object, but wasn't sure if on the right track and didn't went any further with experiments in that direction. Thanks to your post I followed up on it and had my cookies working in short time. :)

Besten Dank nach Graz!