Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Get confirmation that a key has reached JS
Forum Updated to NodeBB v4.3 + New Features

Get confirmation that a key has reached JS

Scheduled Pinned Locked Moved Solved Qt WebKit
webview webkitjscriptkeyevent
33 Posts 4 Posters 13.1k Views 4 Watching
  • 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.
  • M McLion
    12 Dec 2016, 15:28

    Hi

    I have a strange issue that on every second use of key used to navigate in a webView with JS, it simply does not react on it.
    I've added an event viewer to the webView to filter and debug key events received and it shows the key press as well as the release event coming in.
    So far, everything seems OK as far as I can reach it 'code-wise'.
    How can I be sure the key reaches the JS code to tell where to look for this issue (my code, behavior of webKit, PHP, JS on server ....)?

    Thanks for any input to track this down.
    McL

    K Offline
    K Offline
    Konstantin Tokarev
    wrote on 12 Dec 2016, 16:02 last edited by
    #2

    @McLion You can set up handler for keydown or keypress in your JS code and send messages to console

    M 1 Reply Last reply 12 Dec 2016, 16:37
    0
    • M Offline
      M Offline
      McLion
      wrote on 12 Dec 2016, 16:12 last edited by
      #3

      Thanks.
      Sounds like a plan ... going to try and post back.

      1 Reply Last reply
      0
      • K Konstantin Tokarev
        12 Dec 2016, 16:02

        @McLion You can set up handler for keydown or keypress in your JS code and send messages to console

        M Offline
        M Offline
        McLion
        wrote on 12 Dec 2016, 16:37 last edited by
        #4

        @Konstantin-Tokarev

        Should something like the 2 console.log lines below give me some output on the console?
        Excerpt from JS code:

        case(event.keyCode >= 65 && event.keyCode <= 73): /* a..i */
                            var index = 0;
                            var rowNum = event.keyCode - 65;
                            var jBottommenuRows = $(this).children('.row');
                            console.log("JS");
                            console.log(event.keyCode);
        
        K 1 Reply Last reply 12 Dec 2016, 16:41
        0
        • M McLion
          12 Dec 2016, 16:37

          @Konstantin-Tokarev

          Should something like the 2 console.log lines below give me some output on the console?
          Excerpt from JS code:

          case(event.keyCode >= 65 && event.keyCode <= 73): /* a..i */
                              var index = 0;
                              var rowNum = event.keyCode - 65;
                              var jBottommenuRows = $(this).children('.row');
                              console.log("JS");
                              console.log(event.keyCode);
          
          K Offline
          K Offline
          Konstantin Tokarev
          wrote on 12 Dec 2016, 16:41 last edited by
          #5

          @McLion Yes

          M 1 Reply Last reply 12 Dec 2016, 16:43
          0
          • K Konstantin Tokarev
            12 Dec 2016, 16:41

            @McLion Yes

            M Offline
            M Offline
            McLion
            wrote on 12 Dec 2016, 16:43 last edited by
            #6

            @Konstantin-Tokarev

            OK, fine. What if there is nothing ... on the very same console all qDebug() perfectly appear?

            K 1 Reply Last reply 12 Dec 2016, 16:44
            0
            • M McLion
              12 Dec 2016, 16:43

              @Konstantin-Tokarev

              OK, fine. What if there is nothing ... on the very same console all qDebug() perfectly appear?

              K Offline
              K Offline
              Konstantin Tokarev
              wrote on 12 Dec 2016, 16:44 last edited by
              #7

              @McLion No, they go to JS console. You can see it in Inspector, or handle QWebPage::javaScriptConsoleMessage signal

              M 1 Reply Last reply 12 Dec 2016, 16:50
              0
              • K Konstantin Tokarev
                12 Dec 2016, 16:44

                @McLion No, they go to JS console. You can see it in Inspector, or handle QWebPage::javaScriptConsoleMessage signal

                M Offline
                M Offline
                McLion
                wrote on 12 Dec 2016, 16:50 last edited by
                #8

                @Konstantin-Tokarev

                Ahhh ... OK ... Thanks a lot.
                Never saw the 'Inspector' and will try to read it up ... is it also part of webKit in Qt?
                I know the inspector on desktop browser but it won't help because it unfortunately does not show the issue there.
                I'll try (tomorrow) to connect the signal to a slot and use qDebug() in there.

                M 1 Reply Last reply 13 Dec 2016, 14:29
                0
                • M McLion
                  12 Dec 2016, 16:50

                  @Konstantin-Tokarev

                  Ahhh ... OK ... Thanks a lot.
                  Never saw the 'Inspector' and will try to read it up ... is it also part of webKit in Qt?
                  I know the inspector on desktop browser but it won't help because it unfortunately does not show the issue there.
                  I'll try (tomorrow) to connect the signal to a slot and use qDebug() in there.

                  M Offline
                  M Offline
                  McLion
                  wrote on 13 Dec 2016, 14:29 last edited by
                  #9

                  @McLion
                  Activated the inspector with the following line:
                  QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
                  Basically works. However, as soon as I have the inspector turned on my webView's do behave very strange, like they do not get all inputs anymore, and I can not debug the situation.

                  Looks like I need to implement QWebPage::javaScriptConsoleMessage and send the messages back to C++ and debug from there.
                  According docs this is not a signal so I can not simply connect to it.

                  K 1 Reply Last reply 13 Dec 2016, 14:31
                  0
                  • M McLion
                    13 Dec 2016, 14:29

                    @McLion
                    Activated the inspector with the following line:
                    QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
                    Basically works. However, as soon as I have the inspector turned on my webView's do behave very strange, like they do not get all inputs anymore, and I can not debug the situation.

                    Looks like I need to implement QWebPage::javaScriptConsoleMessage and send the messages back to C++ and debug from there.
                    According docs this is not a signal so I can not simply connect to it.

                    K Offline
                    K Offline
                    Konstantin Tokarev
                    wrote on 13 Dec 2016, 14:31 last edited by
                    #10

                    @McLion Right, I've mixed it up with new consoleMessageReceived() signal that is present in revived QtWebKit only (since TP3)

                    M 1 Reply Last reply 13 Dec 2016, 15:42
                    1
                    • K Konstantin Tokarev
                      13 Dec 2016, 14:31

                      @McLion Right, I've mixed it up with new consoleMessageReceived() signal that is present in revived QtWebKit only (since TP3)

                      M Offline
                      M Offline
                      McLion
                      wrote on 13 Dec 2016, 15:42 last edited by
                      #11

                      @Konstantin-Tokarev
                      Need some help ...
                      I have the following:
                      in h:

                      #include <QWebPage>
                      class DBGWebPage : public QWebPage
                      {
                      Q_OBJECT
                        public:
                          explicit DBGWebPage(QObject *parent = 0);
                        protected:
                          void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );
                      };
                      

                      in cpp:

                      void DBGWebPage::javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID )
                      {
                        qDebug() << message << lineNumber << sourceID;
                      }
                      

                      and my webGUI's are derived from qWebView:

                      QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
                      

                      How do I make it use the reimplementation of javaScriptConsoleMessage()?

                      K 1 Reply Last reply 13 Dec 2016, 15:44
                      0
                      • M McLion
                        13 Dec 2016, 15:42

                        @Konstantin-Tokarev
                        Need some help ...
                        I have the following:
                        in h:

                        #include <QWebPage>
                        class DBGWebPage : public QWebPage
                        {
                        Q_OBJECT
                          public:
                            explicit DBGWebPage(QObject *parent = 0);
                          protected:
                            void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );
                        };
                        

                        in cpp:

                        void DBGWebPage::javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID )
                        {
                          qDebug() << message << lineNumber << sourceID;
                        }
                        

                        and my webGUI's are derived from qWebView:

                        QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
                        

                        How do I make it use the reimplementation of javaScriptConsoleMessage()?

                        K Offline
                        K Offline
                        Konstantin Tokarev
                        wrote on 13 Dec 2016, 15:44 last edited by
                        #12

                        @McLion QWebView::setPage

                        M 2 Replies Last reply 13 Dec 2016, 16:24
                        0
                        • K Konstantin Tokarev
                          13 Dec 2016, 15:44

                          @McLion QWebView::setPage

                          M Offline
                          M Offline
                          McLion
                          wrote on 13 Dec 2016, 16:24 last edited by
                          #13

                          @Konstantin-Tokarev
                          Thanks .. seems to be too late for today ... I don't get it to build ... dam...

                          1 Reply Last reply
                          0
                          • K Konstantin Tokarev
                            13 Dec 2016, 15:44

                            @McLion QWebView::setPage

                            M Offline
                            M Offline
                            McLion
                            wrote on 13 Dec 2016, 16:53 last edited by
                            #14

                            @Konstantin-Tokarev
                            There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:

                            #include <QWebPage>
                            class DBGWebPage : public QWebPage
                            {
                            Q_OBJECT
                              public:
                                explicit DBGWebPage(QObject *parent = 0);
                                QWebPage *DebugWebPage;
                              protected:
                                void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );
                            };
                            
                            DBGWebPage::DBGWebPage(QObject *parent) :
                              QWebPage(parent)
                            {
                              //QWebPage* DebugWebPage = new QWebPage;
                              DebugWebPage = new QWebPage(this);
                            }
                            
                            QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID)
                            {
                              // check if already existing
                              if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; }
                            
                              // check for max GUI count here
                              if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; }
                            
                              // create new webGUI and add it to the list
                              QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
                              webGUIMap.insert(iID, webGUI);
                            
                              // make some basic settings to the new GUI
                              webGUI->setPage(DBGWebPage::DebugWebPage);
                              webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID));
                            ......
                            

                            Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'

                            K M 3 Replies Last reply 13 Dec 2016, 16:54
                            0
                            • M McLion
                              13 Dec 2016, 16:53

                              @Konstantin-Tokarev
                              There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:

                              #include <QWebPage>
                              class DBGWebPage : public QWebPage
                              {
                              Q_OBJECT
                                public:
                                  explicit DBGWebPage(QObject *parent = 0);
                                  QWebPage *DebugWebPage;
                                protected:
                                  void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );
                              };
                              
                              DBGWebPage::DBGWebPage(QObject *parent) :
                                QWebPage(parent)
                              {
                                //QWebPage* DebugWebPage = new QWebPage;
                                DebugWebPage = new QWebPage(this);
                              }
                              
                              QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID)
                              {
                                // check if already existing
                                if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; }
                              
                                // check for max GUI count here
                                if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; }
                              
                                // create new webGUI and add it to the list
                                QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
                                webGUIMap.insert(iID, webGUI);
                              
                                // make some basic settings to the new GUI
                                webGUI->setPage(DBGWebPage::DebugWebPage);
                                webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID));
                              ......
                              

                              Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'

                              K Offline
                              K Offline
                              Konstantin Tokarev
                              wrote on 13 Dec 2016, 16:54 last edited by
                              #15
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • M McLion
                                13 Dec 2016, 16:53

                                @Konstantin-Tokarev
                                There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:

                                #include <QWebPage>
                                class DBGWebPage : public QWebPage
                                {
                                Q_OBJECT
                                  public:
                                    explicit DBGWebPage(QObject *parent = 0);
                                    QWebPage *DebugWebPage;
                                  protected:
                                    void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );
                                };
                                
                                DBGWebPage::DBGWebPage(QObject *parent) :
                                  QWebPage(parent)
                                {
                                  //QWebPage* DebugWebPage = new QWebPage;
                                  DebugWebPage = new QWebPage(this);
                                }
                                
                                QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID)
                                {
                                  // check if already existing
                                  if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; }
                                
                                  // check for max GUI count here
                                  if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; }
                                
                                  // create new webGUI and add it to the list
                                  QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
                                  webGUIMap.insert(iID, webGUI);
                                
                                  // make some basic settings to the new GUI
                                  webGUI->setPage(DBGWebPage::DebugWebPage);
                                  webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID));
                                ......
                                

                                Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 13 Dec 2016, 16:57 last edited by
                                #16

                                Hi
                                webGUI->setPage(DBGWebPage::DebugWebPage);
                                I would expect be something like
                                DBGWebPage *page=new DBGWebPage();
                                webGUI->setPage(page->DebugWebPage);

                                The other syntax seems odd ?

                                M 1 Reply Last reply 13 Dec 2016, 17:06
                                0
                                • M McLion
                                  13 Dec 2016, 16:53

                                  @Konstantin-Tokarev
                                  There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:

                                  #include <QWebPage>
                                  class DBGWebPage : public QWebPage
                                  {
                                  Q_OBJECT
                                    public:
                                      explicit DBGWebPage(QObject *parent = 0);
                                      QWebPage *DebugWebPage;
                                    protected:
                                      void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );
                                  };
                                  
                                  DBGWebPage::DBGWebPage(QObject *parent) :
                                    QWebPage(parent)
                                  {
                                    //QWebPage* DebugWebPage = new QWebPage;
                                    DebugWebPage = new QWebPage(this);
                                  }
                                  
                                  QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID)
                                  {
                                    // check if already existing
                                    if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; }
                                  
                                    // check for max GUI count here
                                    if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; }
                                  
                                    // create new webGUI and add it to the list
                                    QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
                                    webGUIMap.insert(iID, webGUI);
                                  
                                    // make some basic settings to the new GUI
                                    webGUI->setPage(DBGWebPage::DebugWebPage);
                                    webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID));
                                  ......
                                  

                                  Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'

                                  K Offline
                                  K Offline
                                  Konstantin Tokarev
                                  wrote on 13 Dec 2016, 17:05 last edited by
                                  #17

                                  @McLion You derive DBGWebPage from QWebPage and add QWebPage* field to it, then try to use that QWebPage* field (which is vanilla QWebPage, not DBGWebPage) as it was static filed of DBGWebPage.

                                  1 Reply Last reply
                                  0
                                  • M mrjj
                                    13 Dec 2016, 16:57

                                    Hi
                                    webGUI->setPage(DBGWebPage::DebugWebPage);
                                    I would expect be something like
                                    DBGWebPage *page=new DBGWebPage();
                                    webGUI->setPage(page->DebugWebPage);

                                    The other syntax seems odd ?

                                    M Offline
                                    M Offline
                                    McLion
                                    wrote on 13 Dec 2016, 17:06 last edited by McLion
                                    #18

                                    @mrjj
                                    Thanks.
                                    In fact, the other syntax seemed wrong.
                                    You code builds without error, however, crashes with SIGSEGV.

                                    K 1 Reply Last reply 13 Dec 2016, 17:21
                                    0
                                    • M McLion
                                      13 Dec 2016, 17:06

                                      @mrjj
                                      Thanks.
                                      In fact, the other syntax seemed wrong.
                                      You code builds without error, however, crashes with SIGSEGV.

                                      K Offline
                                      K Offline
                                      Konstantin Tokarev
                                      wrote on 13 Dec 2016, 17:21 last edited by
                                      #19

                                      @McLion Because it should be

                                      DBGWebPage *page=new DBGWebPage();
                                      webGUI->setPage(page);

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        McLion
                                        wrote on 13 Dec 2016, 17:24 last edited by
                                        #20

                                        I somehow understand all you're saying, but I so far am not able to modify my code to not crash.
                                        Currently ended up with (modified to it while Konstantin was writing it too):

                                        DBGWebPage *page=new DBGWebPage();
                                        webGUI->setPage(page);
                                        

                                        and an empty constructor.
                                        Still crashing .... I'm stumped.

                                        1 Reply Last reply
                                        0
                                        • K Offline
                                          K Offline
                                          Konstantin Tokarev
                                          wrote on 13 Dec 2016, 17:37 last edited by
                                          #21

                                          remove DebugWebPage and all code messing with it

                                          M 1 Reply Last reply 13 Dec 2016, 17:44
                                          0

                                          11/33

                                          13 Dec 2016, 15:42

                                          topic:navigator.unread, 22
                                          • Login

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