I am new to Ubuntu & Qt. I need to show busy status for other long operations. So, I was just trying to use waiting animation gif files to load instead using Progress bars.
I am using Eclipse Editor for Qt project.
Trolltech/../imageformat folder contains libqgif.so and libqgif.so.debug. I have copied these files in my debug folder too.
loader.gif is added in qrc file and kept in /Resources folder
IN MainWindow class I have added label and after setupUi(this) been called I call my ShowMovie() function as below:
ShowMovie() {
QMovie *movie = NULL;
movie = new QMovie(":/Resources/loader.gif");
if(movie->isValid()) {
ui.label_3->setMovie(movie);
movie->start();
}
else
qDebug()<<"Movie is Invalid";
qDebug()<<QImageReader::supportedImageFormats ();
}
Always isValid() function returns false & I got message that Movie is Invalid.
Last qDebug() returns
("bmp", "gif", "ico", "jpeg", "jpg", "mng", "pbm", "pgm", "png", "ppm",
"svg", "svgz", "tif", "tiff", "xbm", "xpm")
i.e means gif support is available.
I have tried to call ShowMovie() function before loading Main UI and/or on button clicked. Both fails.
Provide help on what is to be corrected.
Thank you.
you don't need to copy librairies files *.so.
Try creating the movie object with the full path to loader.gif. Does it work?
Then you have not setup correctly your resource system.
Either you have a syntax mistake in the qrc file which need to be fixed or you forgot to add it as a resource in the project file (.pro) using
RESOURCES = myqresource.qrc
Related
I implemented a application for Sunmi T1 mini device in-build printer in Xamarin forms and i want to print a image with some text like billing receipt.
I integrated AIDL file for Sunmi T1 mini device you can see in image.
But i am facing namespacing issue in IWoyouService.cs "the type of namespace name 'BitmapStub' does not exist in the namespace 'Android.Graphics'."
case TransactionPrintBitmap: {
data.EnforceInterface (descriptor);
Android.Graphics.Bitmap arg0 = default (Android.Graphics.Bitmap);
arg0 = Android.Graphics.BitmapStub.AsInterface (data.ReadStrongBinder ());
ICallback arg1 = default (ICallback);
arg1 = ICallbackStub.AsInterface (data.ReadStrongBinder ());
this.PrintBitmap (arg0, arg1);
reply.WriteNoException ();
return true;
}
I attach my AIDL Zip file https://drive.google.com/file/d/1lrCgZwDrfyqs6LAwTP3pQ6nMzYIW4hrY/view?usp=sharing.
How can resolve this error in Xamarin.Forms
I had this exact same problem, and managed to solve it by adding another AIDL file to define what a 'Bitmap' is.
I copied this file from the Android Open Source Project and just added it into my project and set the build action to Android Interface Definition like the other Sunmi AIDL files.
Not sure why Xamarin doesn't manage to handle this automatically, but adding this solved the problem for me and I was able to build and successfully invoke the interface methods that accept bitmap parameters.
In case the link ever goes bad, here is the entire file you need to add - it's very small:
/* Save this in Bitmap.aidl and add to your project alongside the others */
package android.graphics;
parcelable Bitmap;
I am trying to export a GUI (Student Grade Manager App) I created in eclipse as a JAR file and run it on my desktop. Nothing happens when I double click it (though it does successfully export) at the moment. Here's an screenshot:
GUI Screenshot - Click here
I'm assuming the main issue here is that in my GUI, I am using the File Input stream in the CourseSectionApp.java file (Where the main method is located). It reads a .txt file called "StudentMarks.txt" and that's where it gets all its student data from.:
BufferedReader aFile = new BufferedReader ( new FileReader("Marks.txt"));
model = CourseSection.loadFrom(aFile);
Is there anyway to get this to work? Can I have the .txt file just export with the JAR file so it loads together? OR is there a way to put a sub-window, like modern applications have where the user can go to File->New-> and say, "load from file", and then be allowed to navigate to the .txt file on his computer?
My main goal is to be able to email this to friends and have them use it, but I googled around and only found a few people having similiar issues with not-so-clear answers. And if the JAR file cannot do this, what can? Will making it a .exe change anything?
Screenshot of Marks.txt file
I tried to make this question as legible as possible and if there is any other information I can provide you guys, please let know.
If you don't need to write to the file, including the file as resource in the jar would be your best option. This way you can always be sure the file is available via jar entry name. E.g.
try (InputStream is = getClass().getResourceAsStream("/data/Marks.txt");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr)){
model = CourseSection.loadFrom(br);
}
If you also need to write to the file, you can use FileChooser to open a dialog for choosing a file:
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Marks File");
fileChooser.getExtensionFilters().add(new ExtensionFilter("Text Files", "*.txt"));
File file = fileChooser.showOpenDialog(null); // you could also pass a owner window here
if (file != null) {
// TODO: handle completed file selection by user
}
The issue described in the comments indicates that there is a problem with the classpath though. You need to make sure all required classes are available when the application is run...
I am importing 2 QML files that come with Qt Controls - ScrollBar.qml and Button.qml in my project. I pre-compile all .qml files that I wrote to reduce application launch time. Is there a way to pre-compile these 2 QML files that come as part of the package?
I tried to remove these files from the qml/QtQuick/Controls/ path and placed them in the same folder as my .qml files but it still failed to load. When I reference ScrollBar in my code, it always tries to load ScrollBar.qml from qml/QtQuick/Controls/ path.
Does any one know if it is possible to pre-compile these QMLs at all? If yes, has any one successfully done it?
Appreciate any help. Thank you.
I'm assuming that you're referring to the Qt Quick Compiler as pre-compiling. The simplest way would just be to build the entire Qt Quick Controls module with the Qt Quick Compiler.
If you need to have it within your project, you could try adding an import that contains the Qt Quick Controls import. QQmlEngine::addImportPath() says:
The newly added path will be first in the importPathList().
That statement seems to imply that order matters, and the code confirms it:
QStringList localImportPaths = database->importPathList(QQmlImportDatabase::Local);
// Search local import paths for a matching version
const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(uri, localImportPaths, vmaj, vmin);
for (const QString &qmldirPath : qmlDirPaths) {
QString absoluteFilePath = typeLoader.absoluteFilePath(qmldirPath);
if (!absoluteFilePath.isEmpty()) {
QString url;
const QStringRef absolutePath = absoluteFilePath.leftRef(absoluteFilePath.lastIndexOf(Slash) + 1);
if (absolutePath.at(0) == Colon)
url = QLatin1String("qrc://") + absolutePath.mid(1);
else
url = QUrl::fromLocalFile(absolutePath.toString()).toString();
QQmlImportDatabase::QmldirCache *cache = new QQmlImportDatabase::QmldirCache;
cache->versionMajor = vmaj;
cache->versionMinor = vmin;
cache->qmldirFilePath = absoluteFilePath;
cache->qmldirPathUrl = url;
cache->next = cacheHead;
database->qmldirCache.insert(uri, cache);
*outQmldirFilePath = absoluteFilePath;
*outQmldirPathUrl = url;
return true;
}
}
Your project structure might look something like this:
myproject/
qml/
main.qml
QtQuick/
Controls/
Button.qml
ScrollBar.qml
qmldir
In main.cpp you'd set the path to the qml directory (note that the path will be different depending on whether you're doing an in-source build or a shadow build of your project, so you may want to use a resource file to simplify things):
engine.addImportPath("path/to/qml");
Note that the controls import other types. For example, Button uses the Settings singleton, which comes from the QtQuick.Controls.Private import, so you'd need to copy that into the qml directory, too. Settings loads a certain style for the button (ButtonStyle), which could be any of the styles in this folder, depending on which style is in use.
In short, you need to copy all of the potential dependencies of the QML files you're using.
I'm beginning to learn Qt for use in one of my projects, and what I need to do is create a GUI that allows the user to open a file. I was looking through the examples and I found one of them that has exactly what I need; the problem is that it's also got a whole lot of other stuff, to the point where I have no idea what I'm looking at or what I'm looking for.
Basically, my question is this:
How do I make what you can see below in the image, where after clicking on the button and selecting the relevant file, it shows and stores the file path in the box to the right?
I have already figured out how to make the button open the file dialog, my only problem is getting it to store and display the filepath.
Solved it with this:
void OpenXMLFile::on_File1Button_clicked()
{
file1Name = QFileDialog::getOpenFileName(this,
tr("Open XML File 1"), "/home", tr("XML Files (*.xml)"));
ui->File1Path->setText(file1Name);
}
void OpenXMLFile::on_File2Button_clicked()
{
file2Name = QFileDialog::getOpenFileName(this,
tr("Open XML File 2"), "/home", tr("XML Files (*.xml)"));
ui->File2Path->setText(file2Name);
}
Where this is my GUI:
(The boxes next to the buttons are Line Edits if anyone was wondering)
I want to save a screenshot of a widget in Qt.
I created the following code that should work:
QWidget* activeWidget = getActiveWidget();//a function that returns the current widget.
if (activeWidget == NULL)
{
return;
}
QPixmap screenshot;
screenshot = QPixmap::grabWidget(activeWidget,activeWidget->rect());
if(screenshot.isNull()){
printf("ERROR");
}
bool a= screenshot.save("c:\\temp\\asd.jpg", "JPG", 50);
But unfortunately this does not seem to work.
Does anyone know what the problem is?
In this answer and this forum post, people suggest the following:
Most likely, the plugin which is required to handle .jpg files is not found by your application. In order to resolve this issue, do one of the following things:
If you are doing a static build, add QTPLUGIN += qjpeg to your .pro file or
if you are doing a dynamic build, put the imageformats folder from %QTDIR%\plugins next to your .exe