小编Sil*_*lex的帖子

宽度,高度和implicitWidth/Height之间的差异以及QML中的相应用例

width/heightimplicitWidth/HeightQML有什么区别?应该何时设置隐式维度而不是常规维度?何时应该从组件/项目中询问隐式维度而不是常规维度?

qt qml

34
推荐指数
2
解决办法
6681
查看次数

连接到特定的wifi有时会在Android上失败

我正在创建一个应用程序,它可以列出ListView中所有可用的wifi.如果我选择列表中的一个wifi,它之前被缓存,List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();那么它应该连接到它.如果WifiConfiguration列表不包含所选的wifi,则没有任何反应.我的问题是,有时我从列表中选择一个wifi(我肯定知道它在WifiConfiguration列表中),但它没有连接到它.相反,它连接回以前连接的WiFi.经过一些尝试(一次又一次地选择相同的wifi),它最终连接到它.这有时不会发生.可能是什么问题?这是我的代码片段:

// Go through all the cached wifis and check if the selected GoPro was cached before
for (WifiConfiguration config : configurations) {
    // If it was cached connect to it and that's all
    if (config.SSID != null && config.SSID.equals("\"" + mDrawerListView.getAdapter().getItem(position) + "\"")) {
        // Log
        Log.i("onReceive", "Connecting to: " + config.SSID);
        mWifiManager.disconnect();
        mWifiManager.enableNetwork(config.networkId, true);
        mWifiManager.reconnect();
        break;
     }
}
Run Code Online (Sandbox Code Playgroud)

android android-wifi

9
推荐指数
1
解决办法
2050
查看次数

QML 中的 forceActiveFocus() 与 focus = true

我阅读了有关以下内容的文档:

但仍然不清楚何时应该使用forceActiveFocus()方法将focus属性设置为 true,反之亦然。

qt focus qml

9
推荐指数
1
解决办法
1万
查看次数

如何在QML中正确保存窗口状态

我阅读了Qt Documentations,我查看了SDK提供的一些示例,我从源代码构建了Qt Creator,看看Qt开发者是如何做到的......仍然没有运气.

我正在为Windows和Mac开发跨平台应用程序.在Mac方面我基本上可以尝试我的任何解决方案,所有这些解决方案都能完美运行(我想这要归功于MacOS).另一方面,在Windows上我总是发现某种bug或粗略的行为.

在我进入更多细节之前,我的问题的根源是支持具有不同分辨率的监视器的多个监视器环境.

简而言之,我的两个主要解决方案:

  1. 由于我主要在QML中编写应用程序,因此我使用的ApplicationWindow是主窗口.保存我的状态ApplicationWindowSettings.我的代码考虑了以前保存的位置是否仍然有效(例如,如果应用程序在显示器上关闭时,它已不再可用)...我必须这样做的唯一原因因为Windows会在"外太空"中打开我的应用程序窗口(Mac自动处理).我的应用程序(在Windows上)进入一个非常奇怪的状态,如果我在其中一个监视器上关闭我的应用程序然后我更改其他监视器缩放因子然后我重新打开我的应用程序.它在右侧显示器上打开,但它已经过度缩放,UI元素只是奇怪的浮动.如果我调整窗口大小,一切都恢复正常.
  2. 我将我的QML暴露ApplicationWindow给C++放入QWidget容器,然后QMainWindow通过将其设置为a 来附加到a setCentralWidget.使用这种方法,我可以访问saveGeometryrestoreGeometry自动处理多个监视器定位,但是我在1.中描述的缩放异常仍然存在.

有人解决了吗?在此先感谢任何帮助和欣赏

qt qml qmainwindow qt5.6

6
推荐指数
1
解决办法
844
查看次数

使用objective-c编写的自己的应用程序打开文件

我想知道如何使用我在OS-X中编写的OS X应用程序打开文件.我在Info.plist中注册了文件类型,并且application:openFile:在我的代码中.我通过这篇文章做了一切,标记为已解决.

问题是,只有在我的应用程序运行时将其拖放到我的应用程序上时,这才有效.但是,如果我只是双击我的文件,它就不起作用.它启动我的应用程序,但不是因为如果我拖放它会开始.因此,application:openFile:双击时不会运行的代码,但仅当我拖放文件时才会运行.

编辑:

关于我的代码以及我想要实现的更多细节.我为其他应用程序创建了一个包装器应用程序.让我们将另一个应用程序称为"HelperApp.app".这个HelperApp位于/Contents/我的包装器应用程序的文件夹中.使用包装器应用程序我指定了一个新的文件类型,让我们在Info.plist文件中将其命名为".ha".该文件包含一些参数命令.我试图实现的,当用户点击一个".ha"文件的文件时,我的包装应用程序从该文件读入参数并为HelperApp设置它,然后启动HelperApp.这个HelperApp根据它得到的参数打开不同的东西.您可以在下面查看我的代码.

我有一个AppDelegate.hAppDelegate.mm默认情况下最新的Xcode如何创建它.我AppDelegate.h在"@end"之前添加了这一行:

- (BOOL)processFile:(NSString *)file;
Run Code Online (Sandbox Code Playgroud)

我有这些功能AppDelegate.mm:

#import "AppDelegate.h"
#import "ArgumentParser.h"

@implementation AppDelegate

- (void)dealloc
{
    [super dealloc];
}

- (BOOL)application:(NSApplication *)WrapperApp openFile:(NSString *)filename
{
    return [self processFile:filename];
}

- (BOOL)processFile:(NSString *)file
{
    NSLog(@"The following file has been dropped or selected: %@",file);

    std::string path = [file cStringUsingEncoding:[NSString defaultCStringEncoding]];

    ArgumentParser parser = ArgumentParser();
    parser.getArgumentfromFile(path);
    parser.setArgumentinFile();     // <== This is the "corrupted" function …
Run Code Online (Sandbox Code Playgroud)

macos objective-c

5
推荐指数
1
解决办法
2832
查看次数

在Mac OS X上使用PCL(Point Cloud Library)生成项目

我安装了他们网站上建议的所有依赖项和预编译的PCL库.

安装完所有内容后,我想按照教程生成一个项目.

执行'make'命令后,我收到几个警告和以下两个错误:

37 warnings generated.
Linking CXX executable pcd_write_test
Undefined symbols for architecture x86_64:
  "pcl::PCDWriter::writeASCII(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sensor_msgs::PointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, int)", referenced from:
      pcl::PCDWriter::write(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sensor_msgs::PointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, bool) in pcd_write.cpp.o
  "pcl::PCDWriter::writeBinary(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, sensor_msgs::PointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&)", referenced from:
      pcl::PCDWriter::write(std::__1::basic_string<char, std::__1::char_traits<char>, …
Run Code Online (Sandbox Code Playgroud)

macos linker cmake

5
推荐指数
1
解决办法
1321
查看次数

如何为QML布局中的项目提供特定间距?

我有一个ColumnLayout,其锚点设置为anchor.fill: parent,因此它已经有一个设置维度,这取决于其父维度.

如何添加Rectangles到此中ColumnLayout,从上到下具有特定的间距?

现在我有这个:

ColumnLayout {
  anchors.fill: parent
  spacing: 2

  Rectangle {
    height: 50
    width: 50
    color: "red"
  }
  Rectangle {
    height: 50
    width: 50
    color: "green"
  }
  Rectangle {
    height: 50
    width: 50
    color: "blue"
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,不是通过间距从上到下使用矩形,2而是将Rectangles均匀地布置在中间ColumnLayout.

一种解决方案是将第一个矩形锚定到父级的顶部,然后将其余的矩形一个接一个地锚定,但我想尽可能避免这种情况.

qt qml qt5 qtquick2

5
推荐指数
2
解决办法
4431
查看次数

在SignalTransition期间如何在QML StateMachine中使用Signal的参数

我有一个C ++类,并且可以在QML中创建它。然后我在QML中有一个信号,该信号具有代表该对象的参数。我正在使用,QtQml.StateMachine并且正在使用捕获触发信号SignalTransition。我希望能够将我的信号参数设置为下一个状态SignalTransition触发。在代码中:

这是我的信号在Model.qml中的样子:

signal mySignal(CustomObject customObject)
Run Code Online (Sandbox Code Playgroud)

我在State.qml中的信号转换代码:

import QtQml.StateMachine 1.0 as SM

// SM.State { ...

Model {
    id: model
    // ...
}

SM.SignalTransition {
    targetState: nextState
    signal: model.mySignal
    onTriggered: console.log(customObject) // error here
}

// ... } 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:ReferenceError: customObject is not defined。当我发出信号时,我将我的customObject作为信号的参数传递。

qt qml qt-signals

5
推荐指数
1
解决办法
756
查看次数

如何在 QML 中将 RowLayout 正确拆分为两个相等的字段?

这是一个简单的例子:

RowLayout {
   spacing: 5

   ColumnLayout {
      Text {
         Layout.fillWidth: true
         text: qsTr("Some text")
      }
      Rectangle {
         Layout.fillWidth: true
         height: 100
         color: "red"
      }
   }

   ColumnLayout {
      Text {
         Layout.fillWidth: true
         text: qsTr("Some more text")
      }
      Rectangle {
         Layout.fillWidth: true
         height: 50
         color: "red"
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

这将产生两个相等领域widthRowLayout,但是为什么我必须指定Layout.fillWidth: true为所有的孩子?

这是Layout.fillWidth: trueText组件中删除的相同示例:

RowLayout {
   spacing: 5

   ColumnLayout {
      Text {
         text: qsTr("Some text")
      }
      Rectangle {
         Layout.fillWidth: true
         height: 100
         color: …
Run Code Online (Sandbox Code Playgroud)

qt qml qt5

4
推荐指数
1
解决办法
6174
查看次数

QML 中的尺寸是与设备无关的像素吗?

我正在使用 Qt 5.6.2

如果我这样做:

Item {
   width: 20
   height: 20
}
Run Code Online (Sandbox Code Playgroud)

width和设备的值是height独立的还是精确的像素?

qt qml

4
推荐指数
1
解决办法
3536
查看次数