[gelöst]Kann Preferences Dialog nicht ausführen

Alles rund um die Programmierung mit Qt
Antworten
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

[gelöst]Kann Preferences Dialog nicht ausführen

Beitrag von defenderLQ »

hi

ich habe mir ein Gui und noch dazu extra das PreferencesWindow Dialog
das Dialog will ich via Toolbar button vom gui ausführen.

habe schon eine methode gefunden aber es kommen fehler..
MainWindow.cpp

Code: Alles auswählen


#include <QString>
#include <QtDebug>
#include <QIcon>

#include "MainWindow.h"
#include "Preferences/PreferencesWindow.h"


#define FONT        QFont(tr("Arial"), 8)

/* Images for toolbar icons */
#define IMAGE_CONNECTIONS       ":/images/connections_24x24.png"
#define IMAGE_PEERS        		":/images/peers_24x24.png"
#define IMAGE_SEARCH    		":/images/search_24x24.png"
#define IMAGE_DOWNLOADS      	":/images/downloads_24x24.png"
#define IMAGE_SHARED_FILES   	":/images/sharedfiles_24x24.png"
#define IMAGE_UPLOADS       	":/images/uploads_24x24.png"
#define IMAGE_PREFERENCES       ":/images/preferences_24x24.png"
#define IMAGE_CHAT          	":/images/chats_24x24.png"
#define IMAGE_RSHARE          	":/images/RShare16.png"


/** Constructor */
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
  /* Invoke the Qt Designer generated QObject setup routine */
  ui.setupUi(this);
  


  /* Create the config pages and actions */
  QActionGroup *grp = new QActionGroup(this);
  ui.stackPages->add(new ConnectionsDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_CONNECTIONS), tr("Connections"), grp));
  
  ui.stackPages->add(new PeersDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_PEERS), tr("Peers"), grp));
                     
  ui.stackPages->add(new SearchDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_SEARCH), tr("Search"), grp));
                     
  ui.stackPages->add(new DownloadsDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_DOWNLOADS), tr("Downloads"), grp));
                     
  ui.stackPages->add(new UploadsDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_UPLOADS), tr("Uploads"), grp));
                     
  ui.stackPages->add(new ChatDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_CHAT), tr("Chat"), grp));
                     
  ui.stackPages->add(new SharedFilesDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_SHARED_FILES), tr("Shared Files"), grp));
  
  /* Create the toolbar */
  ui.toolBar->addActions(grp->actions());
  ui.toolBar->addSeparator();
  connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
 
  /* Create and bind the Preferences button */  
  addAction(new QAction(QIcon(IMAGE_PREFERENCES), tr("Preferences"), ui.toolBar),
            SLOT(showPreferencesWindow())); 

  /* Select the first action */
  grp->actions()[0]->setChecked(true);
  
  

 
}

/** Creates a new action associated with a config page. */
QAction*
MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
  QAction *action = new QAction(img, text, group);
  action->setCheckable(true);
  action->setFont(FONT);
  return action;
}

/** Adds the given action to the toolbar and hooks its triggered() signal to
 * the specified slot (if given). */
void
MainWindow::addAction(QAction *action, const char *slot)
{
  action->setFont(FONT);
  ui.toolBar->addAction(action);
  connect(action, SIGNAL(triggered()), this, slot);
}

/** Overloads the default show so we can load settings */
void
MainWindow::show()
{


  if (!this->isVisible()) {
    QMainWindow::show();
  } else {
    QMainWindow::activateWindow();
    setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
    QMainWindow::raise();
  }
}

/** Shows the config dialog with focus set to the given page. */
void
MainWindow::show(Page page)
{
  /* Show the dialog. */
  show();

  /* Set the focus to the specified page. */
  ui.stackPages->setCurrentIndex((int)page);
}

/** Shows Preferences */
void MainWindow::showPreferencesWindow()
{
    PreferencesWindow *preferencesWindow = new PreferencesWindow();
    preferencesWindow->exec();
}




MainWindow.h

Code: Alles auswählen


#ifndef _MainWindow_H
#define _MainWindow_H

#include <QMainWindow>
#include <QFileDialog>


#include "ConnectionsDialog.h"
#include "PeersDialog.h"
#include "SearchDialog.h"
#include "DownloadsDialog.h"
#include "UploadsDialog.h"
#include "ChatDialog.h"
#include "SharedFilesDialog.h"



#include "ui_MainWindow.h"




class MainWindow : public QMainWindow
{
  Q_OBJECT

public:
  /** Main dialog pages. */
  enum Page {
    Connections  = 0,  /** Connections page. */
    Peers     	 = 1,  /** Peers page. */
    Search 		 = 2,  /** Search page. */
    Downloads    = 3,  /** Downloads page. */
    Uploads      = 4,  /** Uploads page. */
    Chat         = 5,  /** Chats page. */
    SharedFiles  = 6   /** Shared Files page. */
  };

  /** Default Constructor */
  MainWindow(QWidget *parent = 0);

public slots:
  /** Called when this dialog is to be displayed */
  void show();
  /** Shows the config dialog with focus set to the given page. */
  void show(Page page);
  

private slots:


  /**void preferences();*/
  
void showPreferencesWindow();
  


private:

  /** Creates a new action for a config page. */
  QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
  /** Adds a new action to the toolbar. */
  void addAction(QAction *action, const char *slot = 0);
  

  


  /** Qt Designer generated object */
  Ui::MainWindow ui;
};

#endif

ok hier nun der fehler:
specs\win32-g++" -o release\MainWindow.o MainWindow.cpp
MainWindow.cpp: In member function `void MainWindow::showPreferencesWindow()':
MainWindow.cpp:126: error: 'class PreferencesWindow' has no member named 'exec'
mingw32-make[1]: *** [release\MainWindow.o] Error 1
mingw32-make[1]: Leaving directory `E:/gui'
mingw32-make: *** [release] Error 2
ok nun was muss ich machen wegen exec?
Zuletzt geändert von defenderLQ am 8. August 2006 22:49, insgesamt 1-mal geändert.
OscarWild
Beiträge: 54
Registriert: 19. Juni 2006 19:59

Beitrag von OscarWild »

defenderLQ hat geschrieben:ok nun was muss ich machen wegen exec?
Nun ja, ich würde sagen - in erster Linie den Quellcode des Moduls hier posten, das das Problem verursacht...
defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

hier mein PreferencesWindow.cpp

Code: Alles auswählen






#include "PreferencesWindow.h"

#define FONT        QFont(tr("Arial"), 8)

/* Images for toolbar icons */
#define IMAGE_PREFERENCES       ":/images/preferences_24x24.png"
#define IMAGE_WEBCACHES        	":/images/webcache_24x24.png"
#define IMAGE_DIRECTORIES    	":/images/shareddirectories_24x24.png"
#define IMAGE_CRYPTOGRAPHY      ":/images/cryptography_24x24.png"
#define IMAGE_LOG   			":/images/log_24x24.png"




/** Constructor */
PreferencesWindow::PreferencesWindow(QWidget* parent)
: QMainWindow(parent)
{
  /* Invoke the Qt Designer generated QObject setup routine */
  ui.setupUi(this);

  /* Create the config pages and actions */
  QActionGroup *grp = new QActionGroup(this);
  ui.stackPages->add(new PreferencesDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_PREFERENCES), tr("Preferences"), grp));
  
  ui.stackPages->add(new DirectoriesDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_DIRECTORIES), tr("Directories"), grp));
                     
  ui.stackPages->add(new WebcachesDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_WEBCACHES), tr("Webcaches"), grp));
                     
  ui.stackPages->add(new CryptographyDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_CRYPTOGRAPHY), tr("Cryptography"), grp));
                     
  ui.stackPages->add(new LogDialog(ui.stackPages),
                     createPageAction(QIcon(IMAGE_LOG), tr("Log"), grp));
                     
  
  /* Create the toolbar */
  ui.toolBar->addActions(grp->actions());
  ui.toolBar->addSeparator();
  connect(grp, SIGNAL(triggered(QAction *)), ui.stackPages, SLOT(showPage(QAction *)));
 

  /* Select the first action */
  grp->actions()[0]->setChecked(true);
}

/** Creates a new action associated with a config page. */
QAction*
PreferencesWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
  QAction *action = new QAction(img, text, group);
  action->setCheckable(true);
  action->setFont(FONT);
  return action;
}

/** Adds the given action to the toolbar and hooks its triggered() signal to
 * the specified slot (if given). */
void
PreferencesWindow::addAction(QAction *action, const char *slot)
{
  action->setFont(FONT);
  ui.toolBar->addAction(action);
  connect(action, SIGNAL(triggered()), this, slot);
}

/** Overloads the default show so we can load settings */
void
PreferencesWindow::show()
{


  if (!this->isVisible()) {
    QMainWindow::show();
  } else {
    QMainWindow::activateWindow();
    setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
    QMainWindow::raise();
  }
}

/** Shows the config dialog with focus set to the given page. */
void
PreferencesWindow::show(Page page)
{
  /* Show the dialog. */
  show();

  /* Set the focus to the specified page. */
  ui.stackPages->setCurrentIndex((int)page);
}

und mein PreferencesWindow.h:

Code: Alles auswählen


#ifndef _PreferencesWindow_H
#define _PreferencesWindow_H

#include <QMainWindow>
#include <QFileDialog>


#include "PreferencesDialog.h"
#include "DirectoriesDialog.h"
#include "WebcachesDialog.h"
#include "CryptographyDialog.h"
#include "LogDialog.h"



#include "ui_PreferencesWindow.h"

class PreferencesWindow : public QMainWindow
{
  Q_OBJECT

public:
  /** Preferences dialog pages. */
  enum Page {
    Preferences  	= 0,  /** Preferences page. */
    Directories  	= 1,  /** Directories page. */
    Webcaches	 	= 2,  /** Webcaches page. */
    Cryptography  	= 3,  /** Cryptography  page. */
    Log      		= 4   /** Log page. */

  };

  /** Default Constructor */
  PreferencesWindow(QWidget *parent = 0);

public slots:
  /** Called when this dialog is to be displayed */
  void show();
  /** Shows the config dialog with focus set to the given page. */
  void show(Page page);

private slots:

  /** Called when user clicks "Help" */
  /**void preferences();*/

private:

  /** Creates a new action for a config page. */
  QAction* createPageAction(QIcon img, QString text, QActionGroup *group);
  /** Adds a new action to the toolbar. */
  void addAction(QAction *action, const char *slot = 0);

  /** Qt Designer generated object */
  Ui::PreferencesWindow ui;
};

#endif

defenderLQ
Beiträge: 156
Registriert: 27. Juli 2006 20:53

Beitrag von defenderLQ »

ok nun statt exec sollte ich show nehmen und schon hats hingehauen....
Antworten