Results 1 to 11 of 11

Thread: Problem pointing to a QStringList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    12
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem pointing to a QStringList

    I wanted to make my application logging, so I added a "QStringList l" to my Mainwindow Class.
    Because the Program has some sub-classes that also should be logging, I added Pointers to the mainwindow's QStringList into them.
    The program executes the Pledge-Algorithm for a robot to leave a room full of blocks, so I created the Classes "CPledge", "CRob" and "CMap".

    The problem: I get a SIGSEGV error when I reference the log-lists of CRob/CMap to the Mainwindow's logList.
    CODE:
    Mainwindow Class:
    Qt Code:
    1. #include <QMainWindow>
    2.  
    3. namespace Ui {
    4. class MainWindow;
    5. }
    6.  
    7. class MainWindow : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. explicit MainWindow(QWidget *parent = 0);
    13. ~MainWindow();
    14.  
    15. // !The Log Object!
    16.  
    17. void saveLog(QString file);
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21.  
    22.  
    23. QString i(int i);
    24. QString dt();
    25.  
    26. private slots:
    27. void on_btStartThread_clicked();
    28. // etc.
    29. };
    30.  
    31.  
    32. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    The CPledge Class (Gets the CRob out of a CMap):
    Qt Code:
    1. class CPledge : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit CPledge(QObject *parent = 0);
    6.  
    7. CMap *map;
    8. CRob *rob;
    9. void setBot(int x, int y);
    10. // Log list reference
    11.  
    12. private:
    13. void followLeftWallTilTurnIsZero();
    14.  
    15. public slots:
    16. void solve(QString filePath);
    17.  
    18. signals:
    19. void finished();
    20. };
    To copy to clipboard, switch view to plain text mode 

    The CMap Class (The Labyrinth):
    Qt Code:
    1. class CMap : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit CMap(QObject *parent = 0);
    6. // Log list reference
    7.  
    8. typedef QList<bool> StonesLine;
    9.  
    10. void loadFromFile(QString FilePath);
    11.  
    12. bool free(int x, int y);
    13. bool left(int x, int y, int turn);
    14. bool front(int x, int y, int turn);
    15. QPoint movedPos(int x, int y, int turn);
    16.  
    17. int cleanTurning(int turn);
    18.  
    19. QPoint *defaultRobPos;
    20.  
    21. private:
    22. // A 2D bool-list: 1->stone; 0-> No stone
    23. QList <StonesLine> stones;
    24. // The list of points where the rob is free
    25. QPoint freePoints[2];
    26.  
    27. void insertBlock(int x1, int y1, int x2, int y2);
    28. void initBlocks(int width, int height);
    29.  
    30. StonesLine horizontalStonesBorder(int width);
    31. StonesLine verticalStonesBorder(int width);
    32. };
    To copy to clipboard, switch view to plain text mode 

    The CRob Class (The Robot):
    Qt Code:
    1. class CRob : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit CRob(QObject *parent = 0);
    6. // Log list reference
    7.  
    8. bool free();
    9.  
    10. bool left();
    11. bool front();
    12.  
    13. void turnR();
    14. void turnL();
    15.  
    16. void move();
    17.  
    18. void setPosition(int newx, int newy);
    19.  
    20. int turning();
    21.  
    22. private:
    23. int x, y;
    24. CMap *map;
    25.  
    26. int fturning;
    27. };
    To copy to clipboard, switch view to plain text mode 


    The Error comes here at Mainwindow.cpp:
    Qt Code:
    1. // etc.
    2. void MainWindow::on_btStartThread_clicked()
    3. {
    4. CPledge *pledge = new CPledge();
    5. pledge->l = &l;
    6. // #########FATAL SIGSEGV ERROR################
    7. pledge->rob->l = &l;
    8. pledge->map->l = &l;
    9.  
    10.  
    11. pledge->solve(ui->edMapPath->text());
    12. }
    13. // etc.
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem pointing to a QStringList

    Get your debugger out and then tell me the values of:

    pledge->rob
    pledge->map
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QStringList problem :/
    By hakermania in forum Qt Programming
    Replies: 9
    Last Post: 17th August 2010, 13:55
  2. qstringlist problem
    By stella1016 in forum Qt Programming
    Replies: 4
    Last Post: 17th December 2009, 09:16
  3. Pointing Two Dimensional Pointer to return value
    By babu198649 in forum General Programming
    Replies: 5
    Last Post: 24th April 2009, 19:16
  4. Replies: 4
    Last Post: 9th January 2009, 11:57
  5. Replies: 7
    Last Post: 2nd June 2006, 12:48

Tags for this Thread

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.