Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Running JS code with JQuerry

Running JS code with JQuerry

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 304 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • TrayonT Offline
    TrayonT Offline
    Trayon
    wrote on last edited by
    #1

    I want to run the following code:

    <!DOCTYPE html>
    <html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script src="qrc:///qtwebchannel/qwebchannel.js"></script>
    </head>
    <body>
    
    <script>
    var processImage;
    $(document).ready(function() {
    new QWebChannel(qt.webChannelTransport, function(channel) {
    mainWindow = channel.objects.mainProjectWindow;
    
    processImage = function getImageData(sourceImageUrl) {
    	function makeBlob (dataURL) {
    	    var BASE64_MARKER = ';base64,';
    	    if (dataURL.indexOf(BASE64_MARKER) == -1) {
    		var parts = dataURL.split(',');
    		var contentType = parts[0].split(':')[1];
    		var raw = decodeURIComponent(parts[1]);
    		return new Blob([raw], { type: contentType });
    	    }
    	    var parts = dataURL.split(BASE64_MARKER);
    	    var contentType = parts[0].split(':')[1];
    	    var raw = window.atob(parts[1]);
    	    var rawLength = raw.length;
    
    	    var uInt8Array = new Uint8Array(rawLength);
    
    	    for (var i = 0; i < rawLength; ++i) {
    		uInt8Array[i] = raw.charCodeAt(i);
    	    }
    
    	    return new Blob([uInt8Array], { type: contentType });
    	}
    
    
    	var subscriptionKey = "can't post this value here";
    	var uriBase = "https://southcentralus.api.cognitive.microsoft.com/face/v1.0/detect?";
    	var params = {
    	    "returnFaceId": "false",
    	    "returnFaceLandmarks": "false",
    	    "returnFaceAttributes": "age,gender"
    	};
    
    	$.ajax({
    	    url: uriBase + "?" + $.param(params),
    	    beforeSend: function(xhrObj){
    		xhrObj.setRequestHeader("Content-Type","application/json");
    		xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
    	    },
    	    type: "POST",
    	    data: '{"url": ' + '"' + sourceImageUrl + '"}',
    	})
    	.done(function(data) {mainWindow.getJSONArray(data);})
    	.fail(function(jqXHR, textStatus, errorThrown) {
    	    var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
    	    errorString += (jqXHR.responseText === "") ? "" : (jQuery.parseJSON(jqXHR.responseText).message) ?
    		jQuery.parseJSON(jqXHR.responseText).message : jQuery.parseJSON(jqXHR.responseText).error.message;
    	    alert(errorString);
    	});
    };
    });
    
    });
    </script>
    
    

    The code that I originally used had a QWebEngineView, which doesn't work on Android; so I was wondering what approach to take to run this code. I saw the options to run JS on QT, but I'm not sure if I can run AJAX or JQuerry with them, so I was wondering if anyone has worked with this before trying the approaches in vain, or if I should take another approach entirely.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved