Is there any way to capture an image of a web page using a C++ CGI? I've been searching high and low, and while I've found a number of implementations in everything from Perl to C#, haven't been able to find any implementations in C++.
The idea is for a user visiting a site to be able to specify a URL. The script would then take a picture of the URL's website, and then show load it to the C++ CGI website I am building.
Any help on this would be much appreciated!
Thanks!
Example in Perl:
Webthumb
You need to render the webpage in order to create a snapshot. To render the page in C++ you need to include a browser engine. You can do this easily using Qt (a toolkit for c++).
This is taken from the documentation of Qt and is all you need to show a webpage.
QWebView *view = new QWebView(ui->centralWidget);
view->load(QUrl("http://qt.nokia.com/"));
view->show();
The view object has a loadFinished signal. You could connect some code to this signal. When the page is rendered you tak a snapshot as described here.
It boils down to:
QPixmap::grabWindow(mainwindow->winId())
When you have got the screenshot you can return the bytes on stdout from your cgi and your done.
Related
I have a doubt and not really sure about how is the best approach, I have a client with a website based on opencart with really bad practices on it, for example, all products are manually placed in the home page instead to be using the CMS capabilities of OC, right now the way it works is, if you are using a computer, full browser, the site displays the full version of the site, but if you are using an ipad or iphone/android device then loads the "small" version, both versions are placed manually in the same home.tpl document and they appear/disappear by some CSS. The question is, the client doesn't want to change the way the home page is designed, so instead to be loading that enormity of code is there a way to have a different tpl for the small version? for example a home.tpl version with the code for the full version and home-mobile.tpl for the small one? how this should work? How the system should determine the screen size and point to a TPL or other TPL?
I know it's a weird request but the client is "happy" with how the site looks like and don't want to change the manual code used on the home page.
CSS is the correct way to handle the resizing and restructuring of the same content on different screens. If you want a vastly different homepage for mobile users, with different content, there are a couple of ways to do it:
Detect the browser using JS and redirect to a mobile-only page. This would probably involve copying your current home controller (and template etc.) to a new file, or using a GET variable to switch templates further down the code.
Detect the browser using PHP, and serve the correct template directly in the code. For this you could use a library like this one (untested, just an example) in your home controller, and change the template path as needed at the bottom of the script.
But first I would really try harder to emphasise to your client that he is doing it wrong.
I am developing the user interface for a embedded device. I have created about 30 ui forms. You have first the Welcome form which loads the database and connects automatically to the available known wifi and all those start up functions. Once everything is loaded the next form to be loaded is the user login
So this is how I go about it, if Login is my second ui
//Instantiating the Login class
Login *myLog = new Login();
//Close the welcome class
this->close();
//open the Login class
myLog->show();
Is this the right way to switch between multiple UI? The software can be imagined like any smart phone device with multiple Icon buttons to open different apps. And each app or folder has a functionality of its own. I have a home button to move back to main menu homepage and so on. I have used the above given code to switch between various ui forms and I am not sure if this is the way to go about it. I am very new to Qt and I was asked to do this task within 2 weeks and I created the easiest way I found. Is there a better way to go about it?
Any help or guidelines is appreciated. If you could give me links to understand better it would be great
Thank you
EDIT
Every ui form has a short cut panel for direct access to login, main menu, settings-power options, wifi options (within settings). The layout flow shown under 1 is similar to 2, 3 and settings. Sorry for the ugly image. The two way arrow indicates i can switch back and forth. The single arrow shows linear movement.
Is there a better way to go about it?
I think so.
As noted in the comment, I would use a QStackedWidget myself.
I think this blog post explains how to establish "Home", "First" and so forth widgets inside it. This should be useful for you:
How to use Qstackedwidget in Qt (Switching between multiple views in Qt)
i thought about making an Url shortener app. That's how the GUI looks like:
Now i have 2 "big" problems because i've never done such things so far.
The first one:
In order to see which checkbox(es) has(have) been checked i need to iterate through them all. How do i do that? because i just dragged&dropped them into my app. I know i should put them into a QListWidget or something like that but i don't know which one.
The second:
How do i submit the link from my app to these url shortener sites and get them back? I'm fairly new to such things. Could you point me to some good tutorials on how to do that? is there an app written in qt so i could look into it's code?
You should use QObject::findChildren()
QList<QCheckBox *> l_checkboxes = parentWidget.findChildren<QCheckBox *>();
where parentWidget is your dialog.
Also, as it performs the search recursively, i would put all checkboxes into a QFrame, QGroupBox, or similar, to reduce the search to such parent widget.
For the second part. It varies for each url shortener. I never worked with em, but, you prolly will have to either:
use the api
Make http post requests as if you were sending
the form from their respective pages.
You can start looking Qt HTTP requests on Google
Right now I am using one webview to show data from my aplicationDatadirectory, here everything is working fine, I get content when user click next back respectively. Now what I am doing is in onload of webview I register "touchevent" and "touchmove" in webview's html like this :-
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
on the basis of this I find swipe event. I get correct html in webview(I can see images). But I am unable to get touchstart and move call. I dont know what is the problem here. I set data in webview using url here.
Now when I set data in webview using html(I used data of my html file(given below) in one var) now I am unable to see images it just shows me one black border(empty) but here my touchstart and touchmove events are firing also my swipe is also working as expected. I am checking this functionality in iPhone.
Can any one find the issue what is going wrong here? Thanks.
I think that this depends on the time when you apply
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
If you use the html property data is loaded immediately and you can use the code exactly after setting html content. If you use the url (even if it is located locally, which might be difficult for android) then you need to wait a short time until the page is loaded. There is also an event listener for that (web view-event load) but i can't say if that works for local resources but i don't think so.
In this case you should apply your javascript snippet into your html resources (if they are locally) instead of manually adding it using evalJS.
Please note that there is an issue on android that you can't use local images (resources folder) in your webview when you provide the content via html property.
I made it swipe working in iOS(in android it was working).
I did not expect this thing to be a reason but I do not know logic behind it. I was accessing .xhtml files from application data directory and it was working without any issue in android but in iOS it was not.
I just change(rename in my code) .xhtml file to .html and now it is working. :)
Hope this can help someone who is looking for the same.(or just for his interest)
Thanks.
I'm working on an OpenCart project. I'm creating a "quick view" effect on the special products on the homepage where if people mouse over the item, a popover displays including a bigger image and an add to cart button.
I'm trying to create an Ajax page where I can use in my js to call and get the details of the product.
My ajax file works fine as far as looking at the passed query string and returning some data; I just don't know how I can include the opencart core files, or module files where I can use to get the details.
I hope I'm making sense.
The easiest and best method would be to use the framework itself and simply use the methods provided to get the data you want. You can read the basics about how to use the framework here assuming you are a php developer and have a basic grasp of OOP and MVC