Results 1 to 6 of 6

Thread: simple question

  1. #1
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default simple question

    what is wrong
    Qt Code:
    1. ----> mainwindow.h
    2. #include <QVBoxLayout>
    3. ...
    4. private:
    5. QVBoxLayout *layoutGrupos;
    6.  
    7. ---->mainwindow.cpp
    8. layoutGrupos = new QVBoxLayout();
    To copy to clipboard, switch view to plain text mode 
    I do not understand what is wrong above

    but when I declare all in the cpp it works ! why ??
    Qt Code:
    1. ---->mainwindow.cpp
    2. QVBoxLayout *layoutGrupos = new QVBoxLayout();
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: simple question

    It would really help if you also tell what error you get.

  3. #3
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simple question

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: simple question

    Post your code

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simple question

    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.

  6. #6
    Join Date
    Jun 2008
    Posts
    20
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: simple question

    Qt Code:
    1. //mainwindow.h
    2.  
    3. #ifndef MAINWINDOW_H
    4. #define MAINWINDOW_H
    5.  
    6. #include <QMainWindow>
    7. #include <QAction>
    8. #include <QVBoxLayout>
    9. #include <QTreeWidget>
    10. #include "login.h"
    11.  
    12. namespace Ui {
    13. class MainWindow;
    14. }
    15.  
    16. class MainWindow : public QMainWindow {
    17. Q_OBJECT
    18. public:
    19. MainWindow(QWidget *parent = 0);
    20. ~MainWindow();
    21.  
    22. protected:
    23. void changeEvent(QEvent *e);
    24.  
    25. private:
    26. Ui::MainWindow *ui;
    27. Login *_login;
    28. QTreeWidget *treeGrupos; // <-- ERROR
    29. QVBoxLayout *layoutGrupos; // <-- ERROR
    30.  
    31. public slots:
    32. void LoginOK();
    33. };
    34.  
    35. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //mainwindow.cpp
    2.  
    3. #include "mainwindow.h"
    4. #include "ui_mainwindow.h"
    5.  
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12.  
    13. _login = new Login(this);
    14. _login->show();
    15.  
    16. treeGrupos = new QTreeWidget(this); // <--- ERROR
    17.  
    18. connect(_login,SIGNAL(loginOK()),this,SLOT(LoginOK()));
    19.  
    20. ui->menuBar->hide();
    21. ui->mainToolBar->hide();
    22. ui->statusBar->hide();
    23. }
    24.  
    25. MainWindow::~MainWindow()
    26. {
    27. delete ui;
    28. }
    29.  
    30. void MainWindow::changeEvent(QEvent *e)
    31. {
    32. QMainWindow::changeEvent(e);
    33. switch (e->type()) {
    34. case QEvent::LanguageChange:
    35. ui->retranslateUi(this);
    36. break;
    37. default:
    38. break;
    39. }
    40. }
    41.  
    42. void MainWindow::LoginOK()
    43. {
    44. //Altera a tela para a tela inicial
    45. ui->stackedWidget->setCurrentIndex(1);
    46. delete _login;
    47.  
    48. //Adiciona tabcontrol
    49. /*QWidget *tabpage2 = new QWidget(ui->tabWidget);
    50. ui->tabWidget->addTab(tabpage2 , "teste");*/
    51.  
    52. ui->tabWidget->setTabText(0,tr("Inicio"));
    53.  
    54. ui->toolBox->removeItem(1);
    55. ui->toolBox->setItemText(0,tr("Grupos"));
    56.  
    57. //Adiciona toolbar em tabcontrol
    58. /*QToolBar *toolbarteste = new QToolBar(tabpage2);
    59. QAction *actionteste = new QAction(toolbarteste);
    60. actionteste->setText("teste TOOLBAR");
    61. toolbarteste->addAction(actionteste);*/
    62.  
    63. layoutGrupos = new QVBoxLayout(ui->Mainwindow_page_1); // <---- ERROR
    64. layoutGrupos->addWidget(treeGrupos);
    65. ui->Mainwindow_page_1->setLayout(layoutGrupos);
    66.  
    67.  
    68. //ui->menuBar->show();
    69. //ui->mainToolBar->show();
    70. //ui->statusBar->show();
    71. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Simple question
    By zorro68 in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2011, 12:42
  2. simple MVC question!
    By landonmkelsey in forum Qt Programming
    Replies: 14
    Last Post: 19th August 2008, 12:25
  3. A simple question
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 6th April 2007, 08:54
  4. simple question
    By mickey in forum Newbie
    Replies: 2
    Last Post: 20th June 2006, 10:39
  5. Another simple question...
    By Dark_Tower in forum Newbie
    Replies: 5
    Last Post: 31st March 2006, 16:13

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
  •  
Qt is a trademark of The Qt Company.