Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Shared library - parameters as pointers or not?
Forum Updated to NodeBB v4.3 + New Features

Shared library - parameters as pointers or not?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 314 Views 1 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.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #1

    Hi,
    I really think that what I am about to ask is a newbie question but I am not sure what would be best practice and why:

    • in my current project I'll have some parts of the code, common methods operating on struct filled with integers, bools and a QVector of bools reused throughout three different standalone applications working as a kind of software suite.
    • Methods return either mentioned struct or QByteArray taking the other as a parameter (so either you have a struct as a parameter and method returns QByteArray or the other way around).
    • I came to the conclusion that it might be better to move those methods to the shared, dynamically loaded library.

    The question: is it ok to just use QByteArray and struct or I should use QByteArray* and struct*?

    For more information please re-read.

    Kind Regards,
    Artur

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It depends on what you want - I don't see a reason why to pass an object as pointer instead as const ref when you don't want to return something in the given object.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      artwawA 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        It depends on what you want - I don't see a reason why to pass an object as pointer instead as const ref when you don't want to return something in the given object.

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @Christian-Ehrlicher Me neither. Parameter is irrelevant and is discarded just after the method finishes, I care only about the return value. But I am often not sure what would be considered good, healthy practice by more experienced fellows in art, so I prefer to ask just to be sure.

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Returning plain pointers results in questions about ownership. Returning objects may be a bottleneck when the object is huge.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          artwawA 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            Returning plain pointers results in questions about ownership. Returning objects may be a bottleneck when the object is huge.

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            @Christian-Ehrlicher got it, thank you!

            For more information please re-read.

            Kind Regards,
            Artur

            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