Results 1 to 3 of 3

Thread: Modify value in child qwt plot

  1. #1
    Join Date
    Apr 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Modify value in child qwt plot

    Dear Qt users & experts,
    I am a noob at Qt, but since it can do nice things it catched my interest, I will try to explain my problem in short :
    I enbedded two qwtplot inside two different groupbox in a mainwindow. In this main window I have a table (made from QabstractItemModel but I can change it). The idea is to click on the graph to get the value where u click. I managed to show this value in a messagebox. Everything worked nicely, except that I have problem for transferring the value to the main window.

    I tried to inherit Plot from MainWindow, but it is normally like : "class Plot : public QwtPlot ....."
    But it seems double inheritance is not good when using connect in further step...

    I have seen also that it seems possible to declare global variables, but I have seen also that it is not recommended, not really in object-oriented programmation spirit.

    I don't know what is the best approach to this problem, can u help me?

  2. #2
    Join Date
    Apr 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Modify value in child qwt plot

    I found a simple way :

    In mainwindow.cpp :
    QString texto="blabla"; // initialisation

    In plot.cpp :
    extern QString texto; // taking extern variable


    Do you think it is a nice way of doing it? Can I use the header maybe?
    I was recently programming in perl and fortran, so I guess I can make things working but I would want to write things in a not dirty way
    It is basically solved, but I would want ur advices to write better code

  3. #3
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Modify value in child qwt plot

    The Qt way of doing this is with their signal/slots mechanism. Basically, you emit/throw a signal when an event happens and you use a slot to catch the event in your main window. If you write the event handler of your Plot to emit this signal, the main window just needs to connect to it.

    Hope that helps!
    Joey

Similar Threads

  1. Replies: 2
    Last Post: 25th February 2015, 18:18
  2. Replies: 2
    Last Post: 13th June 2013, 11:46
  3. Replies: 3
    Last Post: 12th April 2013, 06:18
  4. Replies: 6
    Last Post: 3rd August 2012, 06:48
  5. Replies: 1
    Last Post: 17th April 2012, 10:10

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.