Important: Please read the Qt Code of Conduct -

Question about qobject signals and slots

  • hi all i have a pointer varibale named webpage i havt to update that pointer frequently and its a must the problem is that i have created some connections of it in the constructor of class Mainwinodw but later i change the value of pointer using slots and signals
    when i do that it does not works the connections still work for first one any good way?

  • Moderators

    Yes. Use punctuation and proper spelling. Right now reading your post is not a nice experience.

    As far as I understand it: you have a pointer. You change the object that the pointer POINTS TO a lot. Signals and slots remain connected to "old" objects. Correct?

    If yes, then this is simply expected behaviour - that is how C++ works. If you want to update sign/slot connections, you have to do it manually every time you change the underlying object. Or, I think that QSignalMapper can make your life easier here - but I have not used it myself, so I am not sure. In any case, you can just make a method like "updateConnections()" that would reapply connections.

  • thanks man this solves my one problem:
    i have few questions:
    before creating new signals do i have to disconnect previous signals will not disconnecting will effect memory.
    i have added some actions and a widget to Mainwindow tool bar but the objects still point to the old webpage
    @ ui->mainToolBar->addAction(webpage->pageAction(QWebPage::Back));
    should i add them again when changing value of webpage how do i update them

  • Moderators

    Oh, so you are using WebKit? I have almost no experience there. From your description I gather that most probably your design is wrong. Maybe the webpage object should not change, only it's contents? That wold make your life much easier.

    Disconnecting is probably necessary (see disconnect() docs, there is a nice compact syntax for mass disconnections), as MOC will still try to send signals to all connected slots.

    I don't remember the API for toolbars, take a look at docs. Most probably, you can get the pointer to all actions there, and then modify connections for those pointers.

  • hey man let me tell you my design
    i think you are thinking that i am updating webpage to update its content i know that i dont need to update its content here us my structure:
    i have a variable called tabs which a QTabWidget
    then when i add a new tab i use a subclassed QWebView class named webview
    when the current tab is changed i just update the value of pointer webpage to the new tabs webview
    here webpage is just a pointer so in tool bar actions i need to update them too i ts important for me too keep the current tab in a pointer know i think you can help me

  • can i do this:
    clear the toolbar and then re add the actiopns very problem as currently there are very rare actions but more will come and even plugins will be allowed to do so so there is a problem in that case
    will a double pointer workdoes not work right now and casues many problems

  • Are you trying to add tabs to "this": example?

  • many many many times i have even looked at simple web browser qt quick example and arora too
    i have learnt many hings from arora and these too
    first up this web browser is very simple and not complex as my and i have seen it but my problem does not gets solve

Log in to reply