Let me see if I can somehow make my mud clear. I have a mainwindow widget with a stacked widget. Each stack of the stacked widget is a class that is loaded when the mainwindow is constructed. I have a combo box on two of the stacked widgets that I need to sychronize. I use almost identical code to reload the QSettings info on the first stacked widget and then it passes the information to the second stacked widget but in doing so I get a segmentation fault. So a brief overview of the program is this.
1. Get the id of the last person used via QSettings.
2. Pass this id to the class of the first stacked widget.
3. The first stacked widget will get the corresponding index of the combobox and set it as the current index.
4. The combobox in the first stacked widget creates a signal on the combo box being changed calling the method from the class for the second stacked widget, passing the id.
5. The combobox in the second stacked widget will get the corresponding index of the combobox and set it as the current index.
The code in #3 and #5 are identical.
The problem seems to be that the pointer to the ui class of the second stacked widget gets lost (this is my guess, maybe not even a good guess).

In the class for the second stacked widget, I access the ui classes and manipulate them sucessfully until I call this from the other stacked widget, then I get the segmentation fault. The method gets called sucessfully but it seems like the pointer to the method gets lost.
Here is the relevant code for the main window that references the first stacked widget.
mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4.  
  5. //Forward declaration of classes used
  6. class NamePage;
  7. class ProjectPage;
  8.  
  9. namespace Ui {
  10. class MainWindow;
  11.  
  12. }
  13.  
  14. class MainWindow : public QMainWindow
  15. {
  16. Q_OBJECT
  17.  
  18. public:
  19. explicit MainWindow(QWidget *parent = 0);
  20. ~MainWindow();
  21.  
  22. protected:
  23. void changeEvent(QEvent *e);
  24. void closeEvent (QCloseEvent *event);
  25.  
  26. private:
  27. Ui::MainWindow *ui;
  28. NamePage *name;
  29. ProjectPage *project;
  30.  
  31. };
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include <QtSql>
  2. #include <QSqlError>
  3. #include <QDebug>
  4. #include <QtGui>
  5. #include "namepage.h"
  6. #include "mainwindow.h"
  7. #include "ui_mainwindow.h"
  8. #include "database.h"
  9. #include "projectpage.h"
  10.  
  11. MainWindow::MainWindow(QWidget *parent) :
  12. QMainWindow(parent),
  13. ui(new Ui::MainWindow)
  14. {
  15. ui->setupUi(this);
  16. name=new NamePage(this);
  17. project = new ProjectPage(this);
  18. ui->MainStackWidget->setCurrentIndex(0);
  19. ui->MainStackWidget->addWidget(name);
  20. ui->MainStackWidget->addWidget(project);
  21. readSettings(); //this reads the last used id from the names in the database
  22.  
  23. void MainWindow::readSettings()
  24. {
  25. QSettings settings ("QT Test","Project Manager");
  26. int indexId=settings.value("lastName",0).toInt();
  27. name->restoreName(indexId);//this calls the method to set the combobox to the correct name in the first stacked widget.
  28. }
  29. }
To copy to clipboard, switch view to plain text mode 

namepage.h
Qt Code:
  1. #ifndef NAMEPAGE_H
  2. #define NAMEPAGE_H
  3. #include <QWidget>
  4. class ProjectPage;
  5.  
  6. namespace Ui {
  7. class NamePage;
  8. }
  9.  
  10. class NamePage : public QWidget
  11. {
  12. Q_OBJECT
  13.  
  14. public:
  15. explicit NamePage(QWidget *parent = 0);
  16. ~NamePage();
  17. void restoreName(int);
  18. int getLastName();
  19.  
  20. private:
  21. Ui::NamePage *ui;
  22. NamePage *name;
  23. ProjectPage *project;
  24. void updateNameComboBox();
  25.  
  26. };
  27.  
  28. #endif // NAMEPAGE_H
To copy to clipboard, switch view to plain text mode 

namepage.cpp
Qt Code:
  1. #include <QtGui>
  2. #include <QtSql>
  3. #include "namepage.h"
  4. #include "ui_namepage.h"
  5. #include "projectpage.h"
  6.  
  7. NamePage::NamePage(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::NamePage)
  10. {
  11. ui->setupUi(this);
  12. }
  13.  
  14. void NamePage::restoreName(int id)
  15. {
  16. if (id>=0)
  17. {
  18. int index = ui->cmbName->findData(id);
  19. ui->cmbName->setCurrentIndex(index);
  20. }
  21. else
  22. {
  23. ui->cmbName->setCurrentIndex(0);
  24. }
  25. }
  26. void NamePage::on_cmbName_currentIndexChanged()
  27. {
  28. project->restoreNameCombo(ui->cmbName->itemData(ui->cmbName->currentIndex()).toInt());//this works fine here!
  29.  
  30. }
To copy to clipboard, switch view to plain text mode 

projectpage.h
Qt Code:
  1. #ifndef PROJECTPAGE_H
  2. #define PROJECTPAGE_H
  3. #include <QWidget>
  4.  
  5. class NamePage;
  6.  
  7. namespace Ui {
  8. class ProjectPage;
  9.  
  10. }
  11.  
  12. class ProjectPage: public QWidget
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit ProjectPage(QWidget *parent = 0);
  18. ~ProjectPage();
  19. void restoreName(int);
  20. void restoreNameCombo(int);
  21.  
  22. private:
  23. Ui::ProjectPage *ui;
  24. ProjectPage *project;
  25. NamePage *name;
  26. void updateNameComboBox();
  27.  
  28. };
  29.  
  30. #endif // PROJECTPAGE_H
To copy to clipboard, switch view to plain text mode 

projectpage.cpp
Qt Code:
  1. #include <QDate>
  2. #include <QtGui>
  3. #include <QtSql>
  4. #include <QDebug>
  5. #include "projectpage.h"
  6. #include "ui_projectpage.h"
  7. #include "namepage.h"
  8.  
  9. ProjectPage::ProjectPage(QWidget *parent) :
  10. QWidget(parent),
  11. ui(new Ui::ProjectPage)
  12. {
  13. ui->setupUi(this);
  14. name=new NamePage;
  15. ui->lblDate->setText(QDate::currentDate ().toString());//this ui class reference works
  16. updateNameComboBox();
  17. }
  18. void ProjectPage::updateNameComboBox()
  19. {
  20.  
  21. QSqlQuery query; //all appropriate references were previously implemented not shown for brevity
  22. query.exec("SELECT id,LName, FName FROM name");
  23. ui->cmbSecName->blockSignals(true);
  24. ui->cmbSecName->clear();
  25.  
  26.  
  27. while (query.next())
  28. {
  29. ui->cmbSecName->addItem(query.value (2).toString()+ " "
  30. + query.value (1).toString(),query.value (0).toInt());
  31. ui->cmbSecName->blockSignals(false);
  32.  
  33. }// the above ui methods work
  34. }
  35. void ProjectPage::restoreNameCombo(int cmbId) //this is where the problem lies
  36. {
  37. if (cmbId>=0)
  38. {
  39. int cmbIndex=ui->cmbSecName->findData(cmbId);
  40. ui->cmbSecName->setCurrentIndex(cmbIndex);
  41. }
  42. else
  43. {
  44. ui->cmbSecName->setCurrentIndex(0);
  45. }
  46. }
To copy to clipboard, switch view to plain text mode 
The above method works fine if called within the class itself, but when called from another class it creates the segmentation fault. I am using QT Creator and I searched on how to do a backtrace to post here, but I couldn't find anything that I could figure out. In debugging mode, when I get the segmentation fault at any ui reference the value for the this pointer is "unavailable sychroneous data".

Any ideas what might be going on?