Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:24:35+00:00 2026-06-05T18:24:35+00:00

The title more or less says it all. I create a widget, add it

  • 0

The title more or less says it all. I create a widget, add it to QTabWidget and when I switch to the new tab the app crashes.

preferencestab.h (The widget I want to add)

#ifndef PREFERENCESTAB_H
#define PREFERENCESTAB_H

#include <QWidget>

#include "tab.h"

class PreferencesTab : public QWidget
{
    Q_OBJECT
public:
    explicit PreferencesTab(QWidget *parent = 0);
    ~PreferencesTab();
    int num;

private:


private slots:
};

#endif // PREFERENCESTAB_H

preferencestab.cpp

#include "preferencestab.h"

#include <QDebug>

PreferencesTab::PreferencesTab(QWidget *parent) : QWidget(parent)
{
}

PreferencesTab::~PreferencesTab()
{

}

tabmanager.cpp (subclass of QTabWidget and where I add the new tab)

...
void TabManager::openPreferences()
{
    PreferencesTab *pref = new PreferencesTab();
    int index = this->addTab(pref, "Edit");

    this->setCurrentIndex(index); // It crashes on this line
}

If I remove the line where it crashed it succeeds at creating the new tab but crashes when I manually switch to it.

It must be something stupid but I just can’t find the error. Help Please

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:24:37+00:00Added an answer on June 5, 2026 at 6:24 pm

    Try to debug your application.

    In QtCreator, you start the debug mode by pressing F5 (⌘-Y on macs) instead of Ctrl-R. This will launch a debugger (e.g. GDB) which tells QtCreator (which then tells you) what kind of error occurred. You also can set breakpoints, step through your code and inspect the variable values (before the error occures of course).

    Another option is to print out the variables using qDebug. Candidates are the this pointer, pref and the index variable; check their values.

    That said, the problem which causes the crash is most likely outside the PreferencesTab class, maybe even outside the TabManager class. That the code within a method of a class is executed doesn’t mean that is was a “valid” call (= the this pointer was valid). So checking the this pointer is always a good idea to track calls to null or invalid pointers.

    If TabManager is a QObject, even debugging the this pointer will fail (if it is invalid), because qDebug() << this will ask for the metaObject(), which will be (most likely) an invalid read if the this pointer is invalid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Title more or less says it all. In response to a touchesBegan event, my
The title more or less says it all: I have a function which takes
Well, the title more or less says it all. I sort of understand what
The title more or less says it all. The calls are documented: Here for
Title more or less says it all. Based on this article, I've come up
Title more or less says it all. Specifically, I've become increasingly annoyed that in
As the title says, I'm using Linux, and the folder could contain more than
Title pretty much says it all. The web.config, unchanged from how VS2008SP1 generated it,
Title kinda says it all. The usual SOS command !bpmd doesn't do a lot
More or less everything is in the title, I am looking for a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.