Battery status Problem
-
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:
@#-------------------------------------------------
Project created by QtCreator 2012-04-25T01:13:25
#-------------------------------------------------
QT += core gui
TARGET = gui
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
qmobilityglobal.hFORMS += 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_OBJECTpublic:
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.
-
If you put the mainwindow.h code in instead the project files one, it woul be helpful :-)
-
oops..sorry, updated it. Thanks for pointing that out.
-
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
-
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'@ -
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
-
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);
//}@ -
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;
}
@ -
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'@ -
Hi,
your compile error showed up in the mainwindow.h file, so I removed all things that were not related to that :-)