Skip to content
  • 0 Votes
    3 Posts
    2k Views
    oblivioncthO

    @JohanSolo

    Ah ok, so it is due to the organization of C++ not Qt, and like you said, the difference of a class instances and pointers.

    It has been long time since I've had to use C++ and I never did anything too advance with it other than a text-based adventure game. I generally am more focused on hardware oriented programing such as with C and Verilog, and MATLAB is the only more software (excluding Arduino interaction) oriented language I have decent experience with.

    Thank you for pointing out why there needs to be a difference. I wasn't familar with pointer usage in C++.

  • 0 Votes
    16 Posts
    12k Views
    T

    My apologies, I will create a new thread. Thanks for all your help! (and putting up with my stuff :) )

  • 0 Votes
    3 Posts
    1k Views
    A

    Lets forget for a moment about ctSettings for simplicity.

    A push button emits the signal clicked(). (If you need reaction on different button, you might need another signal)
    This means that to react on the click you need to connect slot of QObject derived class instance to this signal.
    Your MainWindow is such QObject derived class. So you can use it for such purpose.
    I assume it also has access to the button pointer (for example ui->pushButton)
    So now you need a slot. If writeSettings is a regular function just convert it to a slot.

    Now we need to connect signal to slot.
    In MainWindow constructor right after ui element are initialized (setuUi()?) add :
    bool ok = connect(pushButton, SIGNAL(clicked()), this, SIGNAL(writeSettings ())); Q_ASSERT( ok);

    Now writeSettings will be called when button is clicked and settings will be saved.

    About ctSettings. There is no need to use custom class at least for this purpose,

    but you can place all functionality in your custom class and use it if you prefer

    void MainWindow::writeSettings()
    {
    ctSettings s;
    s.writeSettings( ... );
    }

    Now you will need to pass parameters to ctSettings ::writeSettings( ... )
    This better not be pointer to ui, cause you will introduce dependency ctSettings on the ui class which will be changed dynamically during development. Better to limit such dependency to MainWIndow.
    ( This is why you did not want to have ctSettings class )
    In this case you would pass pass individual control like:

    ctSettings s;
    s.writeSettings( const QCheckBox* checkBox1 );

    For all other questions I would recommend C++ book.
    I can't explain what "private" is better than there.
    Just understand that as soon in the code you see variable of specific type (class) mentioned,
    it means compiler needs to know about this class already. Normally this means you have to include proper header file. (There is only one exception when incomplete class declaration is allowed, but book again will explain this much better than me).

    Regards,
    Alex

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    How are you setting up your model ?

  • 0 Votes
    2 Posts
    786 Views
    SGaistS

    Hi,

    Please don't post the same question multiple times, especially on unrelated sub-forum.

    Duplicate

    Closing this one

  • 0 Votes
    4 Posts
    3k Views
    X

    Hi,
    Thank you both for your suggestions!

    As this project is intended for industrial purposes I think XML is a great solution.
    I followed some tutorials on how to use XML on Qt and managed to make it work (as well as understand) pretty well for what I intended to do.

    I'm leaving here the tutorials I followed in case someone stumbles upon this thread with the same problem: (I apologize if this is not allowed)
    https://www.youtube.com/watch?v=NXGE5XUrRSI
    https://www.youtube.com/watch?v=NzQwJdcdRKE
    I had to make some changes to my project but it's easy to understand.

    Thank you, once again!

  • 0 Votes
    4 Posts
    5k Views
    Chris KawaC

    From a design point of view it's not ugly. It's actually prettier.

    For example if you have a class Triangle or APieceOfRock they have conceptually no debugging or to string conversion notion whatsoever.
    Why should a triangle or a piece of rock know anything about strings or how to convert to them? Should it also convert to other data types like ACar or QWidget? Should you add a conversion method to them every time you introduce another type in your app? Making toSting() method in every class is pumping in it functionality that is out of their purpose scope and does not belong to that class.

    A separate utility function, detached from the class is actually a much cleaner solution that keeps responsibility separation.