Results 1 to 11 of 11

Thread: QT WebKit - Browser Interaction Problem

  1. #1
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QT WebKit - Browser Interaction Problem

    Hello everyone, I'm developing a Qt program that contains an OpenStreetMap application as a HTML page and this page is able to access a database -via submitting an ajax form that contains the start and end dates of queries- in order to retrieve and visualize queries on the map. I would like to move this querying process to Qt from the HTML/Javascript part. So far I managed to interact with the browser via Qt but I still have a problem that is below: (by the way, the database is a MySQL database on XAMPP and trying to fetch queries from the HTML window's fetch button works -although it also sometimes shows the POST failed message and then clicking again fetches and shows the queries, I haven't been able to figure that out either-)

    1) The fetch queries button of Qt is clicked and an alert box is supposed to pop up saying that Ajax POST is failed -the database is not on my current laptop and I should be getting the error when I click either the HTML Browser window's fetch queries button or the Qt's fetch button-

    2) But also, whenever I click the Fetch queries button of the HTML Browser, it displays the POST warning but also displays extra POST warning alert boxes depending on how many times I have clicked the Qt's Fetch queries button. -for example if I have clicked the Qt's fetch queries button 5 times in a row and then clicked the HTML window's fetch button once, I get 6 POST failed messages in a row-

    The HTML code is like the following:


    Qt Code:
    1. <form id="ajaxForm" action="index.php" method="post">
    2. Start <input type="text" name = "date1" id = "datepicker" value = "2011-07-13" style = "width:70px">
    3. <input type="text" name = "time1" id = "timepicker1" value = "00:00" style = "width:40px">
    4.  
    5. End <input type="text" name = "date2" id = "datepicker2" value = "2011-07-13" style = "width:70px">
    6. <input type="text" name = "time2" id = "timepicker2" value = "00:01" style = "width:40px">
    To copy to clipboard, switch view to plain text mode 





    The post method of AJAX form is this:



    Qt Code:
    1. <script type="text/javascript">
    2.  
    3. $(document).ready(function(){
    4.  
    5. // ajaxForm submit
    6. $('#ajaxForm').submit(function() {
    7. $.ajax({
    8. type: 'POST',
    9. url: 'heatQuery.php',
    10. data: $(this).serialize(),
    11. dataType: 'json',
    12. success: function(response)
    13. {
    14. // update the points for heatmap layer
    15. updateHeatMap(response);
    16.  
    17. },
    18. error: function(errorMsg)
    19. {
    20. alert('Error in Ajax POST');
    21. }
    22. });
    23.  
    24. return false;
    25. });
    26. });
    27.  
    28. </script>
    To copy to clipboard, switch view to plain text mode 





    And finally, the Qt code that calls the function is this:




    Qt Code:
    1. void MainWindow::onButtonClicked() // clicking the button in order to POST
    2. {
    3. //the QString a is the same ajax post function as declared above
    4.  
    5. QString a = "$(document).ready(function(){$('#ajaxForm').submit(function() {$.ajax({type: 'POST',url: 'heatQuery.php',data: $(this).serialize(),dataType: 'json',success: function(response){updateHeatMap(response);},error: function(errorMsg){alert('Error in Ajax POST');}});return false;});});";
    6.  
    7. this->view->page()->mainFrame()->evaluateJavaScript(a);
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 



    Any ideas on what is wrong here? Thanks.

  2. #2
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QT WebKit - Browser Interaction Problem

    If you don't want to have multiple error messages when clicking several times, make sure you disable the submit button when posting the Ajax request the first time.
    Either disable to submit button or use a var flag to control that.

    I believe something like this would work:

    Qt Code:
    1. <script type="text/javascript">
    2.  
    3. var _ajaxRequestOngoing = false;
    4.  
    5. $(document).ready(function(){
    6.  
    7. // ajaxForm submit
    8. $('#ajaxForm').submit(function() {
    9. if (_ajaxRequestOngoing) return false;
    10.  
    11. _ajaxRequestOngoing = true;
    12. $.ajax({
    13. type: 'POST',
    14. url: 'heatQuery.php',
    15. data: $(this).serialize(),
    16. dataType: 'json',
    17. success: function(response)
    18. {
    19. _ajaxRequestOngoing = false;
    20. // update the points for heatmap layer
    21. updateHeatMap(response);
    22.  
    23. },
    24. error: function(errorMsg)
    25. {
    26. _ajaxRequestOngoing = false;
    27. alert('Error in Ajax POST');
    28. }
    29. });
    30.  
    31. return false;
    32. });
    33. });
    34.  
    35. </script>
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to tferreira for this useful post:

    s7 (22nd May 2012)

  4. #3
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT WebKit - Browser Interaction Problem

    Thanks, that took care of extra POST error messages from HTML but how do I make sure that fetch button of Qt does the same job as HTML's fetch button does? Technically evaluateJavascript should work but I still can't figure out how to invoke that POST from the Qt.

  5. #4
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QT WebKit - Browser Interaction Problem

    JavaScript:
    Qt Code:
    1. <script type="text/javascript">
    2.  
    3. var _ajaxRequestOngoing = false;
    4.  
    5. $(document).ready(function(){
    6.  
    7. // ajaxForm submit
    8. $('#ajaxForm').submit(function() {
    9. formSubmit();
    10. return false;
    11. });
    12. });
    13.  
    14. function formSubmit() {
    15. if (_ajaxRequestOngoing) return false;
    16.  
    17. _ajaxRequestOngoing = true;
    18. $.ajax({
    19. type: 'POST',
    20. url: 'heatQuery.php',
    21. data: $(this).serialize(),
    22. dataType: 'json',
    23. success: function(response)
    24. {
    25. _ajaxRequestOngoing = false;
    26. // update the points for heatmap layer
    27. updateHeatMap(response);
    28.  
    29. },
    30. error: function(errorMsg)
    31. {
    32. _ajaxRequestOngoing = false;
    33. alert('Error in Ajax POST');
    34. }
    35. });
    36. }
    37. </script>
    To copy to clipboard, switch view to plain text mode 

    Qt:
    Qt Code:
    1. void MainWindow::onButtonClicked() // clicking the button in order to POST
    2. {
    3. QString a = "formSubmit();";
    4.  
    5. this->view->page()->mainFrame()->evaluateJavaScript(a);
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    I hope this helps.

  6. The following user says thank you to tferreira for this useful post:

    s7 (22nd May 2012)

  7. #5
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT WebKit - Browser Interaction Problem

    Thanks, now I get the POST error immediately upon clicking the button. But how can I solve the POST error? Queries don't show as they should.. (Also, HTML's fetch button also started to give that error btw)
    Last edited by s7; 22nd May 2012 at 16:26.

  8. #6
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QT WebKit - Browser Interaction Problem

    Is the heatQuery.php file accessible?

    By displaying the error message, maybe it could help you understand what's wrong.

    Qt Code:
    1. error: function(errorMsg)
    2. {
    3. _ajaxRequestOngoing = false;
    4. alert('Error in Ajax POST\n' + errorMsg);
    5. }
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to tferreira for this useful post:

    s7 (22nd May 2012)

  10. #7
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT WebKit - Browser Interaction Problem

    Yes, it's in the D:/xampp/htdocs. When I ran the code it gave the [object XMLHttpRequest] as error.

  11. #8
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QT WebKit - Browser Interaction Problem

    Qt Code:
    1. error: function(jqXHR, textStatus, errorThrown)
    2. {
    3. _ajaxRequestOngoing = false;
    4. alert('Error in Ajax POST\ntextStatus: ' + textStatus + '\nerrorThrown: ' + errorThrown);
    5. }
    To copy to clipboard, switch view to plain text mode 


    More about jQuery.ajax() here: http://api.jquery.com/jQuery.ajax/

  12. The following user says thank you to tferreira for this useful post:

    s7 (22nd May 2012)

  13. #9
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT WebKit - Browser Interaction Problem

    OK I just tried that one and got the following (upon entering the date-time values from the HTML part and clicking the Qt's Fetch queries button):

    Error in Ajax POST
    textStatus: parseerror
    errorThrown: SyntaxError: Unable to parse JSON string

  14. #10
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QT WebKit - Browser Interaction Problem

    You are not returning a valid JSON string.
    Remember that you have set: dataType: 'json'

    http://stackoverflow.com/questions/7...-object-object

    I don't want to sound rude, but you could try and search google before asking some questions
    You'd be amazed to find that others have had the same problems

  15. The following user says thank you to tferreira for this useful post:

    s7 (22nd May 2012)

  16. #11
    Join Date
    May 2012
    Posts
    9
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT WebKit - Browser Interaction Problem

    Thanks a lot, I have been working on this error for the past two days or so and it drove me crazy. That is definitely a starting point for me, will take over from here

Similar Threads

  1. Handling multiple web pages in Qt WebKit Browser
    By dpen41 in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2012, 21:15
  2. Replies: 0
    Last Post: 17th March 2011, 03:17
  3. Not able to run fancy browser and demo browser example applications
    By GoGetIt in forum Installation and Deployment
    Replies: 1
    Last Post: 16th August 2010, 06:23
  4. Problem while using Text browser
    By yuvaraj.yadav in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 13:41
  5. file-browser problem
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 15th November 2007, 05:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.