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. [Solved] Square matrix use
Forum Updated to NodeBB v4.3 + New Features

[Solved] Square matrix use

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.1k 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.
  • D Offline
    D Offline
    doubitchou
    wrote on last edited by
    #1

    From the main of my application I have instantiated a 2D square array/matrix (constant 10x10 dimensions) which I'd like to pass to a Tools class that can read, write save_to_file or read_from_file the different states of that matrix.For example to change the matrix[2][5] = 1 ->2 or be able to save the whole matrix to a file.

    Therefore, I've thought that QGenericMatrix may be appropriated :

    @QGenericMatrix<10,10,int> MyMatrix;@

    to call it with all the methods in _tools _ class like :

    @Tools::write_matrix(unsigned short i, unsigned short j, unsigned short value)@

    My question is then :

    How to be able to call these methods with the matrix instantiation from the main ?

    while it's declared as :

    @QGenericMatrix::QGenericMatrix(const QGenericMatrix<N, M, T> & other)@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can either typedef your matrix type

      @typedef QGenericMatrix<10, 10, int> MyCoolMatrix@

      Or use const QGenericMatrix<10, 10, int> &matrix as parameter of your function.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jafarabadi.qt
        wrote on last edited by
        #3

        Hi,
        You can't access the main function scope in other classes (normal way)
        it's better to pass matrix as one of your function parameters
        or
        put your tools function members in Matrix classes by inherit and after define or overload your functions. :)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          doubitchou
          wrote on last edited by
          #4

          If I'd go with your point of view Jafar I would declare the matrix within the tools class and have just to send coordinates and value from the main as I exposed but write it from within the Tools itself.
          Sometimes I wonder why looking in complicated ways when a simple solution is fine, ie : Occam's razor.

          Thanks to both of you.

          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