Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
shahumang8
Posts: 641
Registered: ‎08-09-2010
My Device: Not Specified
Accepted Solution

duplicate connection name error and after crash application

Hello,

 

        I attached code which throws error of duplicate connection name and after they application crash.

 

      Note :- Into app when you press tab3 at that time they fetch data and another time you press tab3 then application crash,

 

      So please update me asap.

 

Thanks,

Umang.

Please use plain text.
Developer
shahumang8
Posts: 641
Registered: ‎08-09-2010
My Device: Not Specified

Re: duplicate connection name error and after crash application

Still waiting for reply You can find attached code or also i include code here

 

 

qml

 

 

// Default empty project template
import bb.cascades 1.0

TabbedPane {
    id: tabMeniuNavigation
   
    //showTabsOnActionBar: true
    Tab {
        title: qsTr("All")
        id: tab1
        Page {
            Container {
                // define tab content here
                Label {
                    text: qsTr("Tab1")
                    horizontalAlignment: HorizontalAlignment.Center
                    textStyle {
                        base: SystemDefaults.TextStyles.TitleText
                    }
                }
            }
        }
    }
    Tab {
        id: tab2
        title: qsTr("Tab2")
        Page {
            Container {
                // define tab content here
                Label {
                    text: qsTr("Tab2")
                    horizontalAlignment: HorizontalAlignment.Center
                    textStyle {
                        base: SystemDefaults.TextStyles.TitleText
                    }
                }
            }
        }
    }
    Tab {
        id: tab3
        title: qsTr("Tab3")
        content: Page {
            Container {
                ListView {
                    objectName: "otherNoteListView"
                } // ListView
            }
        }
        onTriggered: {
            app.medicialListData();
        }
    }
    Tab {
        id: tab4
        title: qsTr("Tab4")
        Page {
            Container {
                // define tab content here
                Label {
                    text: qsTr("Tab 4")
                    horizontalAlignment: HorizontalAlignment.Center
                    textStyle {
                        base: SystemDefaults.TextStyles.TitleText
                    }
                }
            }
        }
    }
    Tab {
        id: tab5
        title: qsTr("Tab5")
        Page {
            Container {
                // define tab content here
                Label {
                    text: qsTr("Tab5")
                    horizontalAlignment: HorizontalAlignment.Center
                    textStyle {
                        base: SystemDefaults.TextStyles.TitleText
                    }
                }
            }
        }
    }
    onCreationCompleted: {
        // this slot is called when declarative scene is created
        // write post creation initialization here
        console.log("TabbedPane - onCreationCompleted()")

        // enable layout to adapt to the device rotation
        // don't forget to enable screen rotation in bar-bescriptor.xml (Application->Orientation->Auto-orient)
        OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
    }
}

 

cpp

 

   

// Default empty project template

#include "FindMedicin.hpp"
#include "customListMedicinitemfactory.h"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/data/DataAccessError.hpp>

using namespace bb::cascades;
using namespace bb::data;

FindMedicin::FindMedicin(bb::cascades::Application *app) :
		QObject(app) {
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
	qml->setContextProperty("app", this);

	// create root object for the UI
	root = qml->createRootObject<AbstractPane>();
	// set created root object as a scene
	app->setScene(root);
}

FindMedicin::~FindMedicin() {

	QSqlDatabase::removeDatabase(mDbNameWithPath);
	delete medicinListView;
	model->registerUserData();

}

QString FindMedicin::copyFileToDataFolder(const QString fileName) {
	// Since we need read and write access to the file, it has
	// to be moved to a folder where we have access to it. First,
	// we check if the file already exists (previously copied).
	QString dataFolder = QDir::homePath();
	QString newFileName = dataFolder + "/" + fileName;
	QFile newFile(newFileName);

	if (!newFile.exists()) {
		// If the file is not already in the data folder, we copy it from the
		// assets folder (read only) to the data folder (read and write).
		QString appFolder(QDir::homePath());
		appFolder.chop(4);
		QString originalFileName = appFolder + "app/native/assets/" + fileName;
		QFile originalFile(originalFileName);

		if (originalFile.exists()) {
			// Create sub folders if any creates the SQL folder for a file path like e.g. sql/quotesdb
			QFileInfo fileInfo(newFileName);
			QDir().mkpath(fileInfo.dir().path());

			if (!originalFile.copy(newFileName)) {
				qDebug() << "Failed to copy file to path: " << newFileName;
			}
		} else {
			qDebug() << "Failed to copy file data base file does not exists.";
		}
	}

	return newFileName;
}

//Find Pharama
void FindMedicin::medicialListData() {
	CustomListMedicinItemFactory *otherNoteItemFactory =
			new CustomListMedicinItemFactory();
	qDebug() << "MediaList Data Called.";

	// create a data model with sorting keys for firstname and lastname
	model = new GroupDataModel(QStringList() << "field1");

	mDbNameWithPath = copyFileToDataFolder("sql/FindMedicin.db");

	// load the sql data from contacts table
	SqlDataAccess sda(mDbNameWithPath);

	//sda = new SqlDataAccess(mDbNameWithPath, this);
	if (sda.hasError()) {
		DataAccessError err = sda.error();
		//DataAccessError* err = sda.error();
		qWarning() << "SQL error: type=" << err.errorType() << ": "
				<< err.errorMessage();

	}
	QVariant list = sda.execute("select * from medicin_detail");
	// add the data to the model
	qDebug() << list.value<QVariantList>();
	model->setGrouping(ItemGrouping::None);
	model->insertList(list.value<QVariantList>());
	// create a ListView control and add the model to the list
	medicinListView = root->findChild<ListView*>("otherNoteListView");
	medicinListView->setObjectName("");
	medicinListView->setDataModel(model);
	medicinListView->setListItemProvider(otherNoteItemFactory);
}

  

more code into attachement.

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: duplicate connection name error and after crash application

Could you provide a more concise sample or code snippet where this issue occurs?

It may also help to know the OS version and SDK version being used.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Developer
shahumang8
Posts: 641
Registered: ‎08-09-2010
My Device: Not Specified

Re: duplicate connection name error and after crash application

Hi,

 

 

First time all data set into listview but after i click into same tab at that time data load but application crash.

 

And i show log so below message i got

 

 QSqlDatabasePrivate::addDatabase: dupli
cate connection name '/accounts/1000/appdata/com.example.FindMedicin.testDev_FindMedicinc7f06901/data/sql/Databasename.db', old connection removed.
 
 I use SDK :- 10.0.9.1673
 
I know there are some problem into connection or clearing list.But i not get idea.
 
Thanks,
Umang. 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: duplicate connection name error and after crash application

It could be due to trying to create a new database connection every time that tab is brought up. Debugging the medicialListData() method should let you see if this is happening.

 

If you still have issues could you please provide a simplified sample, possibly with only one tab and as little C+ as needed to reproduce the issue? It should make understanding the cause much easier.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: duplicate connection name error and after crash application

The DataSource class may also be helpful, it will let you perform your SQL queries right from QML:
http://developer.blackberry.com/cascades/reference/bb__data__datasource.html
Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Developer
simon_hain
Posts: 16,102
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: duplicate connection name error and after crash application

i also get this warning when i change the sql query of the datasource connected to the listview.
never caused the application to crash though, so i ignored it so far.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.