×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    redefinition of 'MainWindow (qwidget*)'

    Hi!

    I'm starting to build an application with the tutorial (batteryLevel).

    but I have this problem:

    redefinition of 'MainWindow (qwidget*)'

    when try to run the application after use this code

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


    please help me

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Re: redefinition of 'MainWindow (qwidget*)'

    nothing know this problem?

  3. #3
    Nokia Developer Expert
    Join Date
    Sep 2011
    Posts
    382

    Re: redefinition of 'MainWindow (qwidget*)'

    It could be a missing "#endif " in the header file among other things. Please also name the source where you found the tutorial or the steps resulting the problem.

    /0

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Re: redefinition of 'MainWindow (qwidget*)'

    the source is nokia, in the Qt creator there is a tutorial for battery widget.. and so where missed this #endif?

    in header this is the xml file:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QtGui/QMainWindow>
    #include <QSystemDeviceInfo>

    namespace Ui {
    class MainWindow;
    }

    QTM_USE_NAMESPACE

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    enum ScreenOrientation {
    ScreenOrientationLockPortrait,
    ScreenOrientationLockLandscape,
    ScreenOrientationAuto
    };

    explicit MainWindow(QWidget *parent = 0);
    virtual ~MainWindow();

    // Note that this will only have an effect on Symbian and Fremantle.
    void setOrientation(ScreenOrientation orientation);

    void showExpanded();

    private:
    Ui::MainWindow *ui;
    void setupGeneral();

    QSystemDeviceInfo *deviceInfo;
    };

    #endif // MAINWINDOW_H


    -----------

    the problem is in the mainwindow.cpp ---> this: "MainWindow::MainWindow(QWidget *parent):"

    redefinition of MainWindow::MainWindow is the error

  5. #5
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: redefinition of 'MainWindow (qwidget*)'

    Quote Originally Posted by Rugge View Post
    Hi!

    I'm starting to build an application with the tutorial (batteryLevel).

    but I have this problem:

    redefinition of 'MainWindow (qwidget*)'

    when try to run the application after use this code

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


    please help me
    MainWindow::MainWindow(QWidget *parent):
    QMainWindow(parent),
    remove the coma(,) from the end.

    Code:
    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    Regards,
    rahul

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Re: redefinition of 'MainWindow (qwidget*)'

    rahul, nothing change...

  7. #7
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: redefinition of 'MainWindow (qwidget*)'

    Removw the last coma(,) Check this :

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

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Re: redefinition of 'MainWindow (qwidget*)'

    nothing, doesn't work..

    the tutorial say this: Use the constructor to set initial values and make sure that the created object is in a defined state, as illustrated by the following code snippet:

  9. #9
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: redefinition of 'MainWindow (qwidget*)'

    Can you please paste some more content (all line above the line causing error) of your .cpp file?

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Re: redefinition of 'MainWindow (qwidget*)'

    sure!



    Code:
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QtCore/QCoreApplication>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent), ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::setOrientation(ScreenOrientation orientation)
    {
    #if defined(Q_OS_SYMBIAN)
        // If the version of Qt on the device is < 4.7.2, that attribute won't work
        if (orientation != ScreenOrientationAuto) {
            const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
            if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
                qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
                return;
            }
        }
    #endif // Q_OS_SYMBIAN
    
        Qt::WidgetAttribute attribute;
        switch (orientation) {
    #if QT_VERSION < 0x040702
        // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
        case ScreenOrientationLockPortrait:
            attribute = static_cast<Qt::WidgetAttribute>(128);
            break;
        case ScreenOrientationLockLandscape:
            attribute = static_cast<Qt::WidgetAttribute>(129);
            break;
        default:
        case ScreenOrientationAuto:
            attribute = static_cast<Qt::WidgetAttribute>(130);
            break;
    #else // QT_VERSION < 0x040702
        case ScreenOrientationLockPortrait:
            attribute = Qt::WA_LockPortraitOrientation;
            break;
        case ScreenOrientationLockLandscape:
            attribute = Qt::WA_LockLandscapeOrientation;
            break;
        default:
        case ScreenOrientationAuto:
            attribute = Qt::WA_AutoOrientation;
            break;
    #endif // QT_VERSION < 0x040702
        };
        setAttribute(attribute, true);
    }
    
    void MainWindow::showExpanded()
    {
    #if defined(Q_OS_SYMBIAN) || defined(Q_WS_SIMULATOR)
        showFullScreen();
    #elif defined(Q_WS_MAEMO_5)
        showMaximized();
    #else
        show();
    #endif
    }
    void MainWindow::setupGeneral()
    {
        deviceInfo = new QSystemDeviceInfo(this);
    
        ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
    
        connect(deviceInfo, SIGNAL(batteryLevelChanged(int)),
                ui->batteryLevelBar, SLOT(setValue(int)));
    }
    
    MainWindow::MainWindow(QWidget *parent):
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        deviceInfo(NULL)
    {
        ui->setupUi(this);
        setupGeneral();
    }

  11. #11
    Nokia Developer Expert
    Join Date
    Sep 2011
    Posts
    382

    Re: redefinition of 'MainWindow (qwidget*)'

    Edited out the post, overlooked the function definition in the header.
    ?

    /0
    Last edited by Devnull; 2011-12-09 at 13:40.

  12. #12
    Nokia Developer Champion
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: redefinition of 'MainWindow (qwidget*)'

    Compiler is right... You are redefining constructor of MainWindow. One is first function of your file and another is last function. Remove one of them.

  13. #13
    Registered User
    Join Date
    Nov 2011
    Posts
    12

    Re: redefinition of 'MainWindow (qwidget*)'

    but is it a NOKIA source code, how to be not correct?? :S
    however solved thanks, but...


    now, there is a simple method to make a homescreen widget with status battery? Like Nokia Battery Monitor?

    Thanks for answer!
    Last edited by Rugge; 2011-12-30 at 23:18.

Similar Threads

  1. scrollbar in mainwindow how???
    By chandantheracer in forum Qt
    Replies: 1
    Last Post: 2011-03-16, 11:44
  2. Redefinition of class error
    By farmdve in forum Symbian
    Replies: 8
    Last Post: 2010-05-18, 23:20
  3. QThread and MainWindow (Qt designer)
    By darksoul_e in forum Qt
    Replies: 11
    Last Post: 2010-05-18, 14:12
  4. Problem of NULL redefinition.
    By nshankar in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2004-06-15, 17:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •