Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Log Path speichern

Log Path speichern

Scheduled Pinned Locked Moved Solved German
3 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Galilio
    wrote on last edited by
    #1

    Hallo zusammen,

    ich habe enen Qdialog erstellt , der SetupDialog heisst.
    Dieses Dialog hat die Aufgabe den Pfad zu speichern.
    Meine Implementiereung sieht so aus:

    Header File:

    #pragma once
    
    #include <QDialog>
    #include "ui_setupDialog.h"
    
    class SetupDialog : public QDialog
    {
    	Q_OBJECT
    
    public:
    	SetupDialog(QWidget *parent = Q_NULLPTR);
    	~SetupDialog();
    
    	public slots:
    	void accept();
    	void reject();
    
    	/**
    	* Open a file browse dialog to browse the logfile path.
    	*/
    	void browseLogfilePath();
    
    private:
    	void setupSettings();
    
    
    private:
    	Ui::setupDialog ui;
    };
    

    cpp File:

    SetupDialog::SetupDialog(QWidget *parent)
    	: QDialog(parent)
    {
    	ui.setupUi(this);
    	setupSettings();
    }
    
    SetupDialog::~SetupDialog()
    {
    }
    void SetupDialog::setupSettings()
    {
    	// Load logfile directory and name from settings
    	QSettings settings;
    	QString logfileDir = settings.value
    	(
    		Constants::instance()->setupLogfileDirKey(),
    		Constants::instance()->setupLogfileDirDefault()
    	).toString();
    	QString logfileName = settings.value
    	(
    		Constants::instance()->setupLogfileNameKey(),
    		Constants::instance()->setupLogfileNameDefault()
    	).toString();
    	ui.lineEditLogfilePath->setText
    	(
    		logfileDir + logfileName
    	);
    }
    
    
    void SetupDialog::browseLogfilePath()
    {
    	QString logfilePath = QFileDialog::getSaveFileName
    	(
    		this,
    		Constants::instance()->applicationName(),
    		"",								// Default direcory
    		tr("Log (*.log);;All (*.*)"),	// File filter
    		0,
    		QFileDialog::DontConfirmOverwrite
    	);
    	if (!logfilePath.isNull())
    	{
    		// If the logfile path is not null, e. g. the dialog was not 
    		// cancelled, show the new file path
    		ui.lineEditLogfilePath->setText(logfilePath);
    	}
    }
    
    void SetupDialog::accept()
    {
    	// Save changed logfile path, directory and name separately
    	QFileInfo logfileInfo(ui.lineEditLogfilePath->text());
    
    	QSettings settings;
    	settings.setValue
    	(
    		Constants::instance()->setupLogfileDirKey(),
    		logfileInfo.absolutePath().append("/")
    	);
    	settings.setValue
    	(
    		Constants::instance()->setupLogfileNameKey(),
    		logfileInfo.fileName()
    	);
    	settings.sync();
    
    	// Call base accept method
    	QDialog::accept();
    }
    
    void SetupDialog::reject()
    {
    	QDialog::reject();
    }
    

    Die klasse Constants: ist nicht anders als eine Singleton , damit ich sicher bin, dass dieses klassen nur eine Instance hat und nicht mehr.
    Meine problem ist so bald ich den SetupDialog verlasse, dann ist der ausgesuchte Pfad wieder verloren.
    Was mache ich den falsch?

    Danke

    raven-worxR 1 Reply Last reply
    0
    • G Galilio

      Hallo zusammen,

      ich habe enen Qdialog erstellt , der SetupDialog heisst.
      Dieses Dialog hat die Aufgabe den Pfad zu speichern.
      Meine Implementiereung sieht so aus:

      Header File:

      #pragma once
      
      #include <QDialog>
      #include "ui_setupDialog.h"
      
      class SetupDialog : public QDialog
      {
      	Q_OBJECT
      
      public:
      	SetupDialog(QWidget *parent = Q_NULLPTR);
      	~SetupDialog();
      
      	public slots:
      	void accept();
      	void reject();
      
      	/**
      	* Open a file browse dialog to browse the logfile path.
      	*/
      	void browseLogfilePath();
      
      private:
      	void setupSettings();
      
      
      private:
      	Ui::setupDialog ui;
      };
      

      cpp File:

      SetupDialog::SetupDialog(QWidget *parent)
      	: QDialog(parent)
      {
      	ui.setupUi(this);
      	setupSettings();
      }
      
      SetupDialog::~SetupDialog()
      {
      }
      void SetupDialog::setupSettings()
      {
      	// Load logfile directory and name from settings
      	QSettings settings;
      	QString logfileDir = settings.value
      	(
      		Constants::instance()->setupLogfileDirKey(),
      		Constants::instance()->setupLogfileDirDefault()
      	).toString();
      	QString logfileName = settings.value
      	(
      		Constants::instance()->setupLogfileNameKey(),
      		Constants::instance()->setupLogfileNameDefault()
      	).toString();
      	ui.lineEditLogfilePath->setText
      	(
      		logfileDir + logfileName
      	);
      }
      
      
      void SetupDialog::browseLogfilePath()
      {
      	QString logfilePath = QFileDialog::getSaveFileName
      	(
      		this,
      		Constants::instance()->applicationName(),
      		"",								// Default direcory
      		tr("Log (*.log);;All (*.*)"),	// File filter
      		0,
      		QFileDialog::DontConfirmOverwrite
      	);
      	if (!logfilePath.isNull())
      	{
      		// If the logfile path is not null, e. g. the dialog was not 
      		// cancelled, show the new file path
      		ui.lineEditLogfilePath->setText(logfilePath);
      	}
      }
      
      void SetupDialog::accept()
      {
      	// Save changed logfile path, directory and name separately
      	QFileInfo logfileInfo(ui.lineEditLogfilePath->text());
      
      	QSettings settings;
      	settings.setValue
      	(
      		Constants::instance()->setupLogfileDirKey(),
      		logfileInfo.absolutePath().append("/")
      	);
      	settings.setValue
      	(
      		Constants::instance()->setupLogfileNameKey(),
      		logfileInfo.fileName()
      	);
      	settings.sync();
      
      	// Call base accept method
      	QDialog::accept();
      }
      
      void SetupDialog::reject()
      {
      	QDialog::reject();
      }
      

      Die klasse Constants: ist nicht anders als eine Singleton , damit ich sicher bin, dass dieses klassen nur eine Instance hat und nicht mehr.
      Meine problem ist so bald ich den SetupDialog verlasse, dann ist der ausgesuchte Pfad wieder verloren.
      Was mache ich den falsch?

      Danke

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Galilio
      du erstellt dein QSettings Objekt ohne Parameter.
      D.h. du musst QCoreApplication::setOrganizationName() und QCoreApplication::setApplicationName() zuvor aufrufen.
      Oder du setzt eben die Konstruktor Parameter.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • G Offline
        G Offline
        Galilio
        wrote on last edited by
        #3

        Ja
        Es ist genau das was ich tun muss.
        Danke

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved