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] My Qt class and QTableWidget
QtWS25 Last Chance

[SOLVED] My Qt class and QTableWidget

Scheduled Pinned Locked Moved General and Desktop
20 Posts 4 Posters 6.8k Views
  • 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.
  • T Offline
    T Offline
    tucnak
    wrote on last edited by
    #1

    I am writing my "QTemplate" class which have to modify my QTableWidget from UI.

    mainwindow.cpp (in constructor)
    @term = new QTemplate(*ui->templates);@

    qtemplate.h
    @class QTemplate : public QObject
    {
    Q_OBJECT
    public:
    explicit QTemplate(QTableWidget &wgt, QObject *parent = 0);@

    qtemplate.cpp
    @QTemplate::QTemplate(QTableWidget &wgt, QObject *parent) :
    QObject(parent)
    {
    table = &wgt;
    timer = new QTimer(this);
    connect(this,SIGNAL(started()),this,SLOT(placeCells()));
    connect(this,SIGNAL(painted()),this,SLOT(wait()));
    }@

    Program crashes on constructor of function start()

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      There are no errors and warnings while compiling.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        So... what does your debugger tell you?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kxyu
          wrote on last edited by
          #4

          looks ok. what does the debugger say? UPD. ups)

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tucnak
            wrote on last edited by
            #5

            Signal name :
            SIGSEGV
            Signal meaning :
            Segmentation fault

            On a first call to QTableWidget (function clearContents())

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kxyu
              wrote on last edited by
              #6

              so where's the code for that? I don't see any calls in constructor

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                Of what type is member table?
                Where exactly does the crash happen?

                PS:
                While there is no official registry for class name prefixes, it is common sense and highly recommended to not use Q for your own classes, as this is the prefix used by Qt itself. So, to not clash with future Qt versions, you should rename QTemplate to something different.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tucnak
                  wrote on last edited by
                  #8

                  [quote author="Kxyu" date="1321119486"]so where's the code for that? I don't see any calls in constructor[/quote]

                  It in start() function:
                  @void QTemplate::start(int m, int c) {
                  table->clear();
                  msec = m;
                  cells = c;
                  emit started();
                  }@

                  [quote author="Volker" date="1321119539"]Of what type is member table?
                  Where exactly does the crash happen?

                  PS:
                  While there is no official registry for class name prefixes, it is common sense and highly recommended to not use Q for your own classes, as this is the prefix used by Qt itself. So, to not clash with future Qt versions, you should rename QTemplate to something different.[/quote]

                  Declaration of 'table':
                  @QTableWidget* table;@

                  Error on first call to 'table'

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    Check that table is not NULL.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      Kxyu
                      wrote on last edited by
                      #10

                      Ok. Now I don't see where start() is called. Looks like table points to nowhere.

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        tucnak
                        wrote on last edited by
                        #11

                        [quote author="Volker" date="1321119951"]Check that table is not NULL.[/quote]

                        In constructor:
                        @table = &wgt;@
                        It can't be NULL.

                        [quote author="Kxyu" date="1321120089"]Ok. Now I don't see where start() is called. Looks like table points to nowhere. [/quote]

                        In MainWindow:
                        @void MainWindow::startTemplate()
                        {
                        term->start(1200,3);
                        }@

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          Kxyu
                          wrote on last edited by
                          #12

                          i guess we need only one piece of that puzzle - the code of MainWindow constructor

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            tucnak
                            wrote on last edited by
                            #13

                            [quote author="Kxyu" date="1321120692"]i guess we need only one piece of that puzzle - the code of MainWindow constructor[/quote]

                            Please:

                            @MainWindow::MainWindow(QWidget *parent) :
                            QMainWindow(parent),
                            ui(new Ui::MainWindow)
                            {
                            ui->setupUi(this);
                            classicTimer = new QTimer(this);
                            term = new QTemplate(*ui->templates);
                            setWindowIcon(QIcon(":/favicon.png"));
                            setGeometry(150,100,960,670);
                            }@

                            @#ifdef ru_RU
                            "Так что там с пазлом?"
                            #endif@

                            1 Reply Last reply
                            0
                            • K Offline
                              K Offline
                              Kxyu
                              wrote on last edited by
                              #14

                              Ok, we're almost there) What we need to see is the relation between
                              @term = new QTemplate(*ui->templates);@

                              and

                              @table->clear();@

                              so I 'll ask you to show the place where startTemplate is called, the place where that place is called and so on. So you'd better show us the whole code)

                              @#ifdef ru_RU
                              "Разберемся)"
                              #endif@

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                tucnak
                                wrote on last edited by
                                #15

                                [quote author="Kxyu" date="1321121317"]Ok, we're almost there) What we need to see is the relation between
                                @term = new QTemplate(*ui->templates);@

                                and

                                @table->clear();@

                                so I 'll ask you to show the place where startTemplate is called, the place where that place is called and so on. So you'd better show us the whole code)

                                @#ifdef ru_RU
                                "Разберемся)"
                                #endif@
                                [/quote]

                                Can you chat outside DevNet?

                                All my contacts in profile.

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  Kxyu
                                  wrote on last edited by
                                  #16

                                  If you want your questions to be answered in russian you can post them "here":http://developer.qt.nokia.com/forums/viewforum/29/

                                  1 Reply Last reply
                                  0
                                  • T Offline
                                    T Offline
                                    tucnak
                                    wrote on last edited by
                                    #17

                                    OK. I can give you whole my MainWindow code.

                                    @#include "mainwindow.h"
                                    #include "ui_mainwindow.h"

                                    MainWindow::MainWindow(QWidget *parent) :
                                    QMainWindow(parent),
                                    ui(new Ui::MainWindow)
                                    {
                                    ui->setupUi(this);
                                    classicTimer = new QTimer(this);
                                    term = new QTemplate(*ui->templates);
                                    setWindowIcon(QIcon(":/favicon.png"));
                                    setGeometry(150,100,960,670);
                                    // *** Connects of TEMPLATE *** //
                                    connect(ui->templateStart,SIGNAL(clicked()),this,SLOT(startTemplate()));
                                    // *** END connects of TEMPLATE *** //
                                    }

                                    MainWindow::~MainWindow()
                                    {
                                    delete ui;
                                    }

                                    void MainWindow::changeEvent(QEvent *e)
                                    {
                                    QMainWindow::changeEvent(e);
                                    switch (e->type()) {
                                    case QEvent::LanguageChange:
                                    ui->retranslateUi(this);
                                    break;
                                    default:
                                    break;
                                    }
                                    }

                                    void MainWindow::startTemplate()
                                    {
                                    term->start(1200,3);
                                    }@

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on last edited by
                                      #18

                                      The code does not look fishy from what we know. Did you try to compile the program in debug mode and run it through the debugger already? This way you know where it bails out.

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        tucnak
                                        wrote on last edited by
                                        #19

                                        Thanks everybody. I found error and fixed it, so I am closing topic.

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          andre
                                          wrote on last edited by
                                          #20

                                          So, could you please post your solution? It could help others with similar issues.

                                          BTW: topics are closed by moderators, not by users ;-) But you are very much invited to mark your topic as [Solved] by clicking the small edit link next to the first posting in the topic. That allows you to edit the title of the topic.

                                          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