Results 1 to 6 of 6

Thread: 2D Array

  1. #1
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default 2D Array

    Hey everyone,

    I need to print the contents of a 2D array to the screen (command line) for a project I'm working on. Can someone point me in the right direction?

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: 2D Array

    can you print a single element of that array? if so then read about "for loop"

  3. #3
    Join Date
    Sep 2009
    Posts
    72
    Thanked 10 Times in 10 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: 2D Array

    Hi

    looking at ur problem statement, it sounds very simple. however if you are not able to see anything on the console which u have print then do rememeber to modify your pro file with
    Qt Code:
    1. CONFIG+=console
    To copy to clipboard, switch view to plain text mode 

    There a function in Qt called qDebug() go through that might be useful in your case.

  4. #4
    Join Date
    Jan 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2D Array

    Thanks guys,

    I'm actually very familiar with C++ in general, but am very new to Qt. I'm not sure which functions to call to print to a command line for Qt. Whereas in C++ I would do something like:

    Qt Code:
    1. ary[10][10];
    2. for (int i = 0 ; i < 9 ; i++)
    3. for (int k = 0 ; k < 9 ; k++)
    4. cout << ary[i][k] << endl ;
    To copy to clipboard, switch view to plain text mode 

    I have no idea how to produce output using Qt.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 2D Array

    Did u try running the code ? As said by vishwajeet you need to add CONFIG += console in your .pro file.
    Also instead of cout, you may have a look at qDebug

  6. #6
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 2D Array

    Hi ctote,

    You can try the following code as example:

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QDebug>
    3.  
    4. #include <iostream>
    5. #include <cstdlib>
    6. using namespace std;
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication app(argc, argv);
    11.  
    12. ary[10][10];
    13.  
    14. for (int i = 0 ; i < 9 ; i++)
    15. for (int k = 0 ; k < 9 ; k++)
    16. cout << ary[i][k] << endl; // or use qDebug() << ary[i][k];
    17. }
    To copy to clipboard, switch view to plain text mode 

    not forgot of use CONFIG+=console and QT -= gui

Similar Threads

  1. array list!
    By maider in forum Qt Programming
    Replies: 6
    Last Post: 27th July 2009, 16:27
  2. How to get an array of bytes from a DLL?
    By srohit24 in forum Qt Programming
    Replies: 5
    Last Post: 22nd April 2009, 16:11
  3. Min and Max value in array
    By Benjamin in forum Qt Programming
    Replies: 13
    Last Post: 27th February 2009, 14:19
  4. SELECT * > to $array
    By smrtak in forum Qt Programming
    Replies: 7
    Last Post: 10th September 2008, 09:30
  5. array of slots?
    By vonCZ in forum Newbie
    Replies: 10
    Last Post: 19th July 2007, 08:16

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.