PDA

View Full Version : simple question



assismvla
25th May 2010, 02:48
what is wrong


----> mainwindow.h
#include <QVBoxLayout>
...
private:
QVBoxLayout *layoutGrupos;

---->mainwindow.cpp
layoutGrupos = new QVBoxLayout();

I do not understand what is wrong above

but when I declare all in the cpp it works ! why ??


---->mainwindow.cpp
QVBoxLayout *layoutGrupos = new QVBoxLayout();

tbscope
25th May 2010, 05:41
It would really help if you also tell what error you get.

assismvla
26th May 2010, 02:36
It is a run time error.

Starting C:\Projetos\MBS-cliente\debug\MBS-cliente.exe...
C:\Projetos\MBS-cliente\debug\MBS-cliente.exe exited with code -1073741795

The program compiles without error, but when running it closes unexpectedly with an error message from windows.

tbscope
26th May 2010, 06:45
Post your code

squidge
26th May 2010, 08:47
The only difference is that the first requires that the class be allocated memory before you can store the pointer from the new, whilst the second will be stored on the stack.

But without code we can only guess.

assismvla
31st May 2010, 00:30
//mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAction>
#include <QVBoxLayout>
#include <QTreeWidget>
#include "login.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();

protected:
void changeEvent(QEvent *e);

private:
Ui::MainWindow *ui;
Login *_login;
QTreeWidget *treeGrupos; // <-- ERROR
QVBoxLayout *layoutGrupos; // <-- ERROR

public slots:
void LoginOK();
};

#endif // MAINWINDOW_H





//mainwindow.cpp

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


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

_login = new Login(this);
_login->show();

treeGrupos = new QTreeWidget(this); // <--- ERROR

connect(_login,SIGNAL(loginOK()),this,SLOT(LoginOK ()));

ui->menuBar->hide();
ui->mainToolBar->hide();
ui->statusBar->hide();
}

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::LoginOK()
{
//Altera a tela para a tela inicial
ui->stackedWidget->setCurrentIndex(1);
delete _login;

//Adiciona tabcontrol
/*QWidget *tabpage2 = new QWidget(ui->tabWidget);
ui->tabWidget->addTab(tabpage2 , "teste");*/

ui->tabWidget->setTabText(0,tr("Inicio"));

ui->toolBox->removeItem(1);
ui->toolBox->setItemText(0,tr("Grupos"));

//Adiciona toolbar em tabcontrol
/*QToolBar *toolbarteste = new QToolBar(tabpage2);
QAction *actionteste = new QAction(toolbarteste);
actionteste->setText("teste TOOLBAR");
toolbarteste->addAction(actionteste);*/

layoutGrupos = new QVBoxLayout(ui->Mainwindow_page_1); // <---- ERROR
layoutGrupos->addWidget(treeGrupos);
ui->Mainwindow_page_1->setLayout(layoutGrupos);


//ui->menuBar->show();
//ui->mainToolBar->show();
//ui->statusBar->show();
}