Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Battery status Problem
Qt 6.11 is out! See what's new in the release blog

Battery status Problem

Scheduled Pinned Locked Moved General and Desktop
10 Posts 1 Posters 7.5k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    I am trying to make a gui that has a few buttons that will give information for a handheld device. In this case a beagle board. I started the project using Qt widget Project/QT gui application.

    One of the buttons has to show a "Battery Status Bar." I am working on that and am getting some errors. I could use some advice on how to resolve these. I will post the error messages followed by my code.

    @In file included from ..\gui\main.cpp:2:
    ..\gui/mainwindow.h:9: error: expected constructor, destructor, or type conversion before 'namespace'
    ..\gui/mainwindow.h:25: error: 'Ui' has not been declared
    ..\gui/mainwindow.h:25: error: ISO C++ forbids declaration of 'MainWindow' with no type
    ..\gui/mainwindow.h:25: error: expected ';' before '*' token
    mingw32-make.exe[1]: *** [debug/main.o] Error 1
    mingw32-make.exe: *** [debug] Error 2
    00:51:37: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project gui (target: Desktop)
    When executing build step 'Make'@

    Here is what I have for my code:

    gui.pro:

    @#-------------------------------------------------

    Project created by QtCreator 2012-04-25T01:13:25

    #-------------------------------------------------

    QT += core gui

    TARGET = gui
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h
    qmobilityglobal.h

    FORMS += mainwindow.ui

    CONFIG += mobility
    MOBILITY += systeminfo
    @

    mainwindow.h:

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QSysInfo>

    //QTM_USE_NAMESPACE

    namespace Ui {
    class MainWindow;
    class ButtonClicked;
    }
    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private slots:
    void ButtonClicked();

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

    QSysInfo *deviceInfo;
    

    };

    #endif // MAINWINDOW_H@

    main.cpp:

    @#include <QtGui/QApplication>
    #include "mainwindow.h"
    #include "qmobilityglobal.h"

    int main(int argc, char argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    /
    DigitalClock clock;
    clock.show();
    */
    return a.exec();
    }@

    mainwindow.cpp:

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "qmobilityglobal.h"
    #include <QtGui>

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

    // Press Button to see Battery Status Bar
    void MainWindow::ButtonClicked() {
    if (ui->batteryLevelBar->isVisible())
    ui->batteryLevelBar->setVisible(false);
    else
    ui->batteryLevelBar->setVisible(true);
    }

    // Get Battery Info
    void MainWindow::setupGeneral()
    {
    deviceInfo = new QSysInfo(this);
    ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
    connect(deviceInfo, SIGNAL(batteryLevelChanged(int)),
    ui->batteryLevelBar, SLOT(setValue(int)));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    I do not know enough about C++ to figure this one out. Appreciate the help.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      If you put the mainwindow.h code in instead the project files one, it woul be helpful :-)

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        oops..sorry, updated it. Thanks for pointing that out.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          Hi,

          I had to comment out some stuff, especially the mobility things and then i could compile it. so perhaps it's something inside qmobilityglobal.h ?

          I just tried it on windows with Qt 4.7.3

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            Can you share what you commented out? I commented out the #include qmobilityglobal.h lines and get these errors:

            @..\gui\mainwindow.cpp: In member function 'void MainWindow::setupGeneral()':
            ..\gui\mainwindow.cpp:28: error: no matching function for call to 'QSysInfo::QSysInfo(MainWindow* const)'
            c:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qglobal.h:1526: note: candidates are: QSysInfo::QSysInfo()
            c:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qglobal.h:1526: note: QSysInfo::QSysInfo(const QSysInfo&)
            ..\gui\mainwindow.cpp:29: error: 'class QSysInfo' has no member named 'batteryLevel'
            ..\gui\mainwindow.cpp:31: error: no matching function for call to 'MainWindow::connect(QSysInfo*&, const char*, QProgressBar*&, const char*)'
            c:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qobject.h:204: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
            c:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qobject.h:217: note: static bool QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
            c:\QtSDK\Desktop\Qt\4.8.1\mingw\include/QtCore/qobject.h:337: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
            mingw32-make.exe[1]: Leaving directory `C:/Users/sabrina/Documents/Sabrina/QT Creator/Projects/senior project/gui-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug'
            mingw32-make.exe[1]: *** [debug/mainwindow.o] Error 1
            mingw32-make.exe: *** [debug] Error 2
            02:12:54: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
            Error while building project gui (target: Desktop)
            When executing build step 'Make'@

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              Hi,

              I commented out:

              mainwindow.h:

              • nothing

              mainwindow.cpp:

              • lines: 3, 13, 18-21, 27-30

              main.cpp:

              • line 3

              pro file:

              • removed the qmobilityglobal.h file

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                Did you mean 18-23?
                @// Press Button to see Battery Status Bar
                //void MainWindow::ButtonClicked() {
                // if (ui->batteryLevelBar->isVisible())
                // ui->batteryLevelBar->setVisible(false);
                // else
                // ui->batteryLevelBar->setVisible(true);
                //}@

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  Hi,

                  no, just the content of the method:

                  @
                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  // #include "qmobilityglobal.h"
                  #include <QtGui>

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

                  // Press Button to see Battery Status Bar
                  void MainWindow::ButtonClicked() {
                  // if (ui->batteryLevelBar->isVisible())
                  // ui->batteryLevelBar->setVisible(false);
                  // else
                  // ui->batteryLevelBar->setVisible(true);
                  }

                  // Get Battery Info
                  void MainWindow::setupGeneral()
                  {
                  // deviceInfo = new QSysInfo(this);
                  // ui->batteryLevelBar->setValue(deviceInfo->batteryLevel());
                  // connect(deviceInfo, SIGNAL(batteryLevelChanged(int)),
                  // ui->batteryLevelBar, SLOT(setValue(int)));
                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }
                  @

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #9

                    yes, but doesnt that basically get rid of what I want to do with the progress bar and battery status? I think I should be using QSystemDeviceInfo instead of QSysInfo, but I cant seem to find that file. When I add a QML file with the following:

                    @import QtMobility.systeminfo 1.2@

                    But then I get the folowing error message:

                    @In file included from ..\gui\main.cpp:2:
                    ..\gui/mainwindow.h:32: error: ISO C++ forbids declaration of 'QSystemDeviceInfo' with no type
                    ..\gui/mainwindow.h:32: error: expected ';' before '*' token
                    mingw32-make.exe[1]: *** [debug/main.o] Error 1
                    mingw32-make.exe: *** [debug] Error 2
                    09:55:18: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
                    Error while building project gui (target: Desktop)
                    When executing build step 'Make'@

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #10

                      Hi,

                      your compile error showed up in the mainwindow.h file, so I removed all things that were not related to that :-)

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      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