Reply
Thread Tools
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#1
Yesterday I did get alot of stuff working for my new program wich made me bit excited as this is my first Qt program. I did reach a point where almost everything worked but I got some problem on the way there. The first is how I update a xml file with new elements and update attributes in a element. I use DOM since I heard it is the best for doing manipulations. And here is my code for making the xml:

Code:
int XML::saveNewEx(QString &name, QString &group, QString &muscle, QString &info)
{
    QDomDocument doc( "Exercises" );
    QDomElement root = doc.createElement( "exercise" );
    doc.appendChild( root );

    root.appendChild(ContactToNode(doc, name, group, muscle, info));

    QFile file( "/home/user/MyDocs/Gym/exercises.xml" );
    if(!file.open(QIODevice::WriteOnly))
        return 1;

    QTextStream ts( &file );
    ts << doc.toString();

    file.close();
    return 0;
}

QDomElement XML::ContactToNode( QDomDocument &d, QString name, QString group, QString muscle, QString info)
{
   QDomElement cn = d.createElement( "exercise" );

   cn.setAttribute( "name", name );
   cn.setAttribute("group", group);
   cn.setAttribute( "muscle", muscle );
   cn.setAttribute( "info", info );
   cn.setAttribute( "weight", "0" );
   cn.setAttribute( "status", "ok" );

   return cn;
}
Secondly I am using phonon to make a small sound. But as I am listening to music while training I have to pause the music before the sound comes. Better would be if it faded out then played the sound and at last faded in.
A link wich describe this using the dbus, but I do not understand this thing... http://talk.maemo.org/showthread.php...ia+player+dbus

The third problem I have is rotation of the screen. I got it working by seting the attribute to portrait or almost... When I add a new exercise I want to write the name and such so I thought that landscape would be much better here. When I create the landscape-window I set the attribute to landscape(for that window). But it does not work, and as I also have set the attribute(portrait) for every window and remove the first windows attribute only some becomes portrait and yet I have not figured out how this really work. So where do I have the set this argument? Do I have to do something before? Or not do?

And the last problem is about vibration! And here is the code for it:
Code:
interface = new QDBusInterface(MCE_SERVICE, MCE_REQUEST_PATH,
                                   MCE_REQUEST_IF, QDBusConnection::systemBus(),
                                   this);

    QDBusMessage reply = interface->call(MCE_ENABLE_VIBRATOR);
    if (reply.type() == QDBusMessage::ErrorMessage)
        qDebug() << reply.errorMessage();

void WaitWindow::vibrate()
{
    QDBusMessage reply;

    reply = interface->call(MCE_ACTIVATE_VIBRATOR_PATTERN, "PatternIncomingCall");
    if (reply.type() == QDBusMessage::ErrorMessage)
        qDebug() << reply.errorMessage();
}

void WaitWindow::stopVibrate()
{
    QDBusMessage reply;

    reply = interface->call(MCE_DEACTIVATE_VIBRATOR_PATTERN, "PatternIncomingCall");
    if (reply.type() == QDBusMessage::ErrorMessage)
        qDebug() << reply.errorMessage();
}
The problem is that if I first call vibrate() and immediately stopVibrate() it does not start at all. If I take a sleep(~500)(bad way I know) in the middle it does not start either. But if I call vibrate and then create a single-shot timer with the interval of 5000 it does start(three vibrates). The problem here is that I want to make this happend ~3 times(independent on the other calls). So when I call it for the second time(one vibrate now) and the third time it does not start at all.

Code for the timer to call vibrate and stopVibrate
Code:
vibrate();
tmr = new QTimer(this);
                tmr->isSingleShot();
                QObject::connect(tmr, SIGNAL(timeout()), this, SLOT(stopVibrate()));
                tmr->start(5000);
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#2
Solved the xml part!
 
Posts: 16 | Thanked: 11 times | Joined on Dec 2009
#3
Originally Posted by Lullen View Post

Code for the timer to call vibrate and stopVibrate
Code:
vibrate();
tmr = new QTimer(this);
                tmr->isSingleShot();
                QObject::connect(tmr, SIGNAL(timeout()), this, SLOT(stopVibrate()));
                tmr->start(5000);
"tmr->isSingleShot();"

I assume that you're trying to trigger a single shot timer here.
"tmr->setSingleShot(true);" would be the right choice in that case. Or you could use the static method "QTimer::singleShot(5000, this, SLOT(stopVibrate()));"
 

The Following 2 Users Say Thank You to rkm For This Useful Post:
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#4
Great, now two out of four problems solved. Soon this should be ready for testing
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#5
I just realised that when I dont have any attributes (portrait) on the mainwindow and I open a new window (with attribute) it is still in landscape. But when I open a new window from the second window (with attribute, same as the last window) it goes into portrait mode. And when I go back from the third window to the second it rotates so it is also in portrait.

To get the second window in portrait mode I could also open or close the keyboard when in the second window...
 
ZogG's Avatar
Posts: 1,389 | Thanked: 1,857 times | Joined on Feb 2010 @ Israel
#6
not that great in programming but maybe you should check when the program is checking when it's in portrait mode or not and when the accelerometres are activited and is it before or after the window opens
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#7
Did not really understand what you ment I guess but I dont use the accelerometer do to the rotation this is a portrait-program with only one window in landscape(this one needs text-input). From what I have read you should set this attribute when the window is created wich I do and it works for one window but not the other with the same code :S
 
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#8
Still have the same old problems, but I got a new problem. How do I interact with the calendar? I know of the calendar-backend-dev example but the development guide tells me to install calendar-backend (wich I have the newest version of) and calendar-backend-dev(wich does not exist). So my thoughts are that this is removed with qt 4.6. If it is, is there any new examples or so for the new calendar api?
 
Posts: 432 | Thanked: 645 times | Joined on Mar 2009
#9
Hi,

Originally Posted by Lullen View Post
Still have the same old problems, but I got a new problem. How do I interact with the calendar? I know of the calendar-backend-dev example but the development guide tells me to install calendar-backend (wich I have the newest version of) and calendar-backend-dev(wich does not exist). So my thoughts are that this is removed with qt 4.6. If it is, is there any new examples or so for the new calendar api?
which development environment are you using? The calendar-backend-dev should be still there and has nothing to do with qt4.6. If you are using scratchbox have you installed the nokia-binaries and is the repository still active in your /etc/apt/sources.list file? Or are you trying it on device?

Daniel
 

The Following User Says Thank You to danielwilms For This Useful Post:
Posts: 289 | Thanked: 101 times | Joined on Oct 2009
#10
Hmm, strange. I am using the new nokia qt sdk with the device(pr 1.2 installed)... When I type in #include <CCalender.h> it tells me that I do not have the file.
 
Reply


 
Forum Jump


All times are GMT. The time now is 06:47.