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. [solved] How to use a public Qwebelement variable
Forum Update on Monday, May 27th 2025

[solved] How to use a public Qwebelement variable

Scheduled Pinned Locked Moved Qt WebKit
9 Posts 3 Posters 3.7k 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.
  • L Offline
    L Offline
    luisvargast
    wrote on last edited by
    #1

    Hello, when I try to use the Qwebelement as a public variable, it doesn't work. For this reason I want to know what am I doing wrong?

    This is my code:

    Header
    @private: QWebElement *element;

    @

    Cpp
    @
    element = ui->webView->page()->currentFrame()->findFirstElement("#"+ElementID);

    @

    However the compiler send me some errors and I am not sure how to solve that

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      Can you provide a little more code (method were it happens and class) and errors thrown by compiler.

      It's impossible to help with given information.


      Code is poetry

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luisvargast
        wrote on last edited by
        #3

        The code is the next

        header
        @
        private:
        QWebElement *element;
        @

        Cpp
        @

        void HtmlEditor::on_webView_selectionChanged()
        {
        element = ui->webView->page()->currentFrame()->
        findAllElements(":hover").last();
        qDebug() << element.attribute("style")
        << element.attribute("id")
        << element.attributeNames() <<
        element.classes()
        ;
        ElementID = element.attribute("id");
        ui->ElementIDlineEdit->setText(ElementID);
        }@

        The errors are the next
        @error: cannot convert 'QWebElement' to 'QWebElement*' in assignment@

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #4

          Your problem is right there in the compiler error. You are trying to asign a QWebElement object (as returned by "QWebElementCollection::last()":http://qt-project.org/doc/qt-4.8/qwebelementcollection.html#last ) to a QWebElement pointer.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jake007
            wrote on last edited by
            #5

            As KA51O and compiler said. You are trying to assign value to pointer type value.

            You have to change your element pointer to object:
            @private:
            QWebElement element; // No more *@

            or change in your on_webView_selectionChanged() method:
            @*element = ui->webView->page()->currentFrame()->
            findAllElements(":hover").last(); // notice * in the front@

            In second case, because element is pointer, you need to change element. to element->


            Code is poetry

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luisvargast
              wrote on last edited by
              #6

              Thanks the second case works perfect, but I need to construct the variable first.

              Other way would be like this

              @void HtmlEditor::on_webView_selectionChanged()
              {
              element = new QWebElement(ui->webView->page()->currentFrame()->
              findAllElements(":hover").last());
              ...
              }@

              In this case I don't need a previus constructor.

              The complete code would be the next

              Header
              @
              private:
              QWebElement *element;@

              Cpp
              @void HtmlEditor::on_webView_selectionChanged()
              {
              element = new QWebElement(ui->webView->page()->currentFrame()->
              findAllElements(":hover").last());
              qDebug() << element->attribute("style")
              << element->attribute("id")
              << element->attributeNames() <<
              element->classes()
              ;
              ElementID = element->attribute("id");
              ui->ElementIDlineEdit->setText(ElementID);
              }@

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jake007
                wrote on last edited by
                #7

                I'm glad you got it working :) .
                The code I wrote was brain to terminal, so there might be a mistake or two.

                Please, mark thread as solved.

                Regards,
                Jake


                Code is poetry

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luisvargast
                  wrote on last edited by
                  #8

                  How do I do that?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jake007
                    wrote on last edited by
                    #9

                    Just edit your first post and add [SOLVED] in front of the title.


                    Code is poetry

                    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